I have my MVC5 Web controller and trying to do a dependency injection using:
public class PatientsController : Controller
{
public ISomeRepository _repo;
// GET: Patients
public ActionResult Index(ISomeRepository repo)
{
_repo = repo;
return View();
}
}
My Unity configuration looks like following:
public static class UnityConfig
{
public static void RegisterComponents()
{
var container = new UnityContainer();
// register all your components with the container here
// it is NOT necessary to register your controllers
// e.g. container.RegisterType<ITestService, TestService>();
container.RegisterType<ISomeRepository, SomeRepository>();
// GlobalConfiguration.Configuration.DependencyResolver = new UnityDependencyResolver(container);
GlobalConfiguration.Configuration.DependencyResolver = new UnityResolver(container);
}
But when I am navigating to controller, getting error:
[MissingMethodException: Cannot create an instance of an interface.]
repointo the controller constructor.