1

I have a bit of an issue. I'm trying to put a "session" class into my container. I want it to stay alive, while this user is on the site. It will simply contain various information, that I will use across my controllers.

I assume, but I am not entirely sure, that LifeStylePerWebRequest is what I need.

BUT, when I use that, it seems to create a new Session class, every single time I submit the page. Maybe this makes sense, if it's per web-request..

So, have I misunderstood PerWebRequest? Does it really create a new class every time I do a postback?

What else can I do? Singleton seems to work, but then all visitors will share the same instance, right?

devnull
  • 118,548
  • 33
  • 236
  • 227
Nicolai
  • 2,835
  • 7
  • 42
  • 52

1 Answers1

0

PerWebRequest creates a brand new instance on each request, but same instance will be reused during same request in case your component will be needed (by other component dependencies) more then once.

If you need a lifestyle tight to the session you may have to wrote your own lifestyle or, if fits your needs, simply have singleton that internally use the session.

Have a look to hybrid lifestyles

Crixo
  • 3,060
  • 1
  • 24
  • 32