0

I'm fairly new to StructureMap. I'm trying to create a session-scoped singleton class (using MVC4 with Sitecore). After some googling i came up with this:

x.For<IMyClass>().LifecycleIs(new HttpSessionLifecycle()).Use<MyClass>();

Issue is that MyClass is instantiated with another class instance

x.For<ISomeAPIClient>()
                .HttpContextScoped()
                .Use((context) => GetApiClient(context));

and this instance, when called from MyClass, does not appear to have access to HttpContext Session - it is null. I think i've tried every built-in lifecycle and have ended up either with the same result or the class not behaving as a session-scoped singleton.
What am i doing wrong?

JPx
  • 1
  • 1
  • From what you wrote, it looks like session is not enabled for your request or is not created yet. At which point of request lifecycle do you try to instantiate the object? – Marek Musielak Dec 23 '15 at 14:10
  • @Marek Musielak I'm not entirely sure. As i said, I'm new to StructureMap. All of the code included in my initial post is from a GlobalContainer configuration. It was my understanding that MyClass would be initialized upon first call, which would mean it'd be during some part of the lifecycle when session is available, because that's what happens when it's set as simply HttpContextScoped(). – JPx Dec 23 '15 at 15:29
  • Related: https://stackoverflow.com/questions/17702546/structuremap-warns-caution-when-injecting-in-session-why – Steven Dec 26 '15 at 13:30

0 Answers0