I’m using both types of controllers available in MVC 4: System.Web.Mvc.Controller and System.Web.Http.ApiController. I need to be able to inject dependencies into the controllers using Unity.
For the ApiControllers I am using Unity.WebApi:
GlobalConfiguration.Configuration.DependencyResolver = new Unity.WebApi.UnityDependencyResolver(_container);
For the Controllers I tried using Unity.Mvc3 which I added using Nuget:
DependencyResolver.SetResolver(new Unity.Mvc3.UnityDependencyResolver(_container));
However, I get a runtime error:
Could not load file or assembly ‘System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35’ or one of its dependencies. The system cannot find the file specified.
Does anyone know of a solution that works for this situation?
Thanks
Add a binding redirect in your web.config: