views:

252

answers:

1

I'm working with Ninject on a web application, using the BasePage and BaseMaster from the frameworks's integrations. What I would like to do is have an object injected and have a new instance created on each session. I've looked at the OnePerRequest behavior and it's close, but not quite. What I'm doing is performing a lot of calculations, and those variables are held in objects that are injected into the page. I need those objects to stay around for postbacks, but I want a new instance of the objects each time the user "Visits" the site. My initial thinking was to use the Asp.net Session object in some way to store the values between postbacks, This is the way I would do it before Ninject (just store the objects in session. but I'd like to use Ninject in the correct way if I can. I'm open to other suggestions. I thought about using the Singleton, but each user is going to need their own copy of the object, otherwise they'll step on each others calculations.

I hope that is clear, and I would appreciate any advice on either using an existing behavior or creating my own. Perhaps using the application cache or the builtin ASP.NET caching could work.

Thank you

Josh

+1  A: 

What you seem to be looking for is 'OnePerSessionBehavior'. I found another StackOverflow post by someone who already implemented this, perhaps you can ask that user for the code:

Frank Geerlings