18

With structuremap 2.6.4.1 my container is configured like this:

existingContainer.Configure(expression =>
{
    expression.For<IDocumentSession>()                    
        .HybridHttpOrThreadLocalScoped()
        .Use(container =>
        {
            var store = container.GetInstance<IDocumentStore>();                        
            return store.OpenSession();
         });
}

HybridHttpOrThreadLocalScoped does not exist in structure map 3 so my question is, what is the equivalent configuration in structuremap 3?

marcus
  • 9,616
  • 9
  • 58
  • 108
  • You should be very careful with Per Thread lifestyles. Take a look at this Q/A: https://stackoverflow.com/questions/14591422/why-is-perthreadlifetimemanager-used-in-this-example. – Steven Apr 13 '14 at 13:05
  • @Steven that's an inaccurate assessment of structuremap it will only fallback to a thread lifetime if there is no context available like inside a unit/integration test. `HybridHttpOrThreadLocalScoped` is one of the very best features of structuremap – Chris Marisic Apr 10 '15 at 19:15
  • @ChrisMarisic: I disagree with you. Even in a unit test it is bad, because this will prevent tests from running in isolation. But even if you use per-thread lifestyle in your unit tests, this is still not a good reason to use this `HybridHttpOrThreadLocalScoped` in your production configuration, because in case of the absence of a HTTP context, an object will live for the duration of the application; hardly ever a good idea. – Steven Apr 10 '15 at 21:06
  • We're going to just disagree then. `HybridHttpOrThreadLocalScoped` is an ultimate reason to use StructureMap and i use it in every project i use StructureMap – Chris Marisic Apr 10 '15 at 21:08

2 Answers2

27

As of StructureMap 3, anything HttpContext related lives within a separate Nuget package called StructureMap.Web which can be found here.

The reason for this is StructureMap 3 is now PLC (Portalble Class Library) compliant, so splitting web-related lifecycles into its own package makes sense.

Joseph Woodward
  • 9,191
  • 5
  • 44
  • 63
  • I think you should answer his question. I don't see any hybrid approach inside StructureMap.Web. – BillRob May 07 '14 at 19:40
  • 2
    It's in there, look inside of [CreatePluginFamilyExpressionExtensions.cs](https://github.com/structuremap/structuremap/blob/master/src/StructureMap.Web/CreatePluginFamilyExpressionExtensions.cs) – Joseph Woodward May 08 '14 at 10:30
2

It is there, says here http://jeremydmiller.com/2014/03/31/structuremap-3-0-is-live/ that is now a Structuremap.Web nuget to add to your project for it to work.

Alex Rouillard
  • 777
  • 8
  • 9