Question

Can you inject a session reference into your class via structure map

Was it helpful?

Solution

Yes.

If you are referring to the HTTP Session for the current user, try adding this to your container registration code:

For<HttpSessionStateBase>().TheDefault.Is.ConstructedBy(() => new HttpSessionStateWrapper(HttpContext.Current.Session));

Now any class retrieved via StructureMap that takes an HttpSessionStateBase as one of its constructor parameters should get the current session.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top