Bia Securities

Archive for June, 2012

Configuring MVC 4 with StructureMap

by on Jun.25, 2012, under Uncategorized

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:

DependencyResolver.SetResolver(new StructureMapDependencyResolver(ObjectFactory.Container));

Hope this helps someone looking to do the same! 

3 Comments more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!