I'm trying to configure Unity IoC in ASP.NET Web Api project. I have made installation of Unity.WebAPI package:
PM > Install-Package Unity.MVC4
And added the next code to Initialise method of Bootstrapper class:
DependencyResolver.SetResolver(new UnityDependencyResolver(container));
Also I have registered my repository in container:
container.RegisterType<IProductRepository, ProductRepository>();
But my App crashes with the error Type 'MvcApplication1.Controllers.ValuesController' does not have a default constructor.
Could someone point me out what have I missed? I use .Net Framework 4.5. Which package of Unity is OK for my purposes (Unity.WebAPI, Unity.MVC4, ...)?
Updated: Injection of repository into controller:
private readonly IProductRepository _repository;
public ValuesController(IProductRepository repository)
{
_repository = repository;
}
ValuesControlleras well as it seems the error is in conjunction with that, what methods are there inside that controller, which one did you (try to) call? - DrCopyPasteI have made installation of Unity.WebAPI, but then you installUnity.MVC4which one was it now, what are you building? MVC application or Web API application? - DrCopyPaste