Upgrading to StructureMap 3
Posted on Saturday, 19th April 2014
Note: For anyone arriving to this post looking for the StructureMap 3 documentation then its official home is here. The documentation isn’t all there, but Jeremy Miller (author of StructureMap) is making his way through writing the new documentation.
As explained in previous blog posts, I’m a huge fan of StructureMap and use it as my IoC container of choice when writing .NET applications. With the release of StructureMap 3, I was happy to see there have been some rather large updates to it. However, when I tried to update an application from version 2 to StructureMap 3 I quickly ran into some configuration issues as a result of the API changes, and with StructureMap 3 being as new as it is there’s little documentation at the moment. Eventually I managed to figure out where missing classes have been moved to so I thought I’d document it here to help anyone who experienced similar head scratching questions.
Q1: HttpContext related scoping has moved
Updating my .NET MVC application that uses HttpContext I quickly became aware that HybridHttpOrThreadLocalScoped had vanished, but I noticed this has now been moved into a separate StructureMap.Web Nuget package that can be found here. It can also be found within Visual Studio’s package manager by simply searching for “StructureMap.Web”. Added this package to my solution quickly resolved the HttpContext related issues I ran into.
Jeremy Miller did mention this on his blog, however I seemed to have skimmed over little detail as I rushed to update like an excited kid at Christmas.
Q2: SetAllProperties(), where are you?
SetAllProperties has now been moved into a class called Policies and can be accessed like so: this.Policies.SetAllProperties();
Enjoy this post? Don't be a stranger!
Follow me on Twitter at @_josephwoodward and say Hi! I love to learn in the open, meet others in the community and talk Go, software engineering and distributed systems related topics.