What is the equivalent of HybridHttpOrThreadLocalScoped in structure map 3?
Asked Answered
P

2

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?

Prem answered 13/4, 2014 at 9:7 Comment(4)
You should be very careful with Per Thread lifestyles. Take a look at this Q/A: #14591922.Sardou
@Sardou 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 structuremapLaunch
@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.Sardou
We're going to just disagree then. HybridHttpOrThreadLocalScoped is an ultimate reason to use StructureMap and i use it in every project i use StructureMapLaunch
R
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.

Rohr answered 16/4, 2014 at 12:57 Comment(2)
I think you should answer his question. I don't see any hybrid approach inside StructureMap.Web.Suanne
It's in there, look inside of CreatePluginFamilyExpressionExtensions.csRohr
R
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.

Residuum answered 15/4, 2014 at 18:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.