I started a new MVC4 project and wanted to use StructureMap for my IOC container of choice. I followed Phil’s post about wiring up dependency resolvers in mvc 4, but I kept getting the following error: “StructureMapDependencyResolver does not appear to implement Microsoft.Practices.ServiceLocation.IServiceLocator.
Parameter name: commonServiceLocator”
Took a little digging, but I found the CommonServiceLocator project from the Microsoft Patterns and Practice group. That project has a StructureMap implementation of the IServiceLocator interface for StructureMap. After I installed the CommonServiceLocator nuget, I was able to reference IServiceLocator in my code. Taking the code from the CommonServiceLocator implementation, I ended up with the following:
This will allow you to specify the default dependency resolver by: