Contents tagged with structuremap

  • A Gentle Introduction to StructureMap

    I found myself explaining inversion of control containers and their benefits to someone today, and so I created a very simple console application that makes use of StructureMap (my favorite such container).  You can view the whole file in this Gist.  Here I’ll just briefly explain what’s going on. The main benefit of a tool like StructureMap is to decouple your classes from their collaborators.  Rather than classes knowing exactly which implementations they’re working with, they publish their needs for collaborators in their constructors, providing explicit dependencies (see my other posts on dependencies).  The IoC container then is used to provide these classes with the … more

  • Getting StructureMap to Work with MVC4 RC and Web API

    At the moment (18 July 2012) if you install the NuGet package structuremap.MVC4, it will not compile due to breaking changes in the ASP.NET MVC4 RC distribution.  You have to jump through some extra hoops to get this working.  Here are two posts that help: Configuring MVC4 with StructureMap Using the Web API Dependency Resolver However, even with both of these getting things working wasn’t quite as easy as I would have liked.  Here are two full files with namespaces showing what I used to get things working (Gist 3135943).  I assume the NuGet package will be updated to be correct once MVC4 ships. more