Using ASP.NET Session for Lifetime Management (Unity)

Posted by Sigray on Stack Overflow See other posts from Stack Overflow or by Sigray
Published on 2009-04-01T20:07:46Z Indexed on 2010/05/17 14:30 UTC
Read the original article Hit count: 242

Filed under:
|
|
|

I am considering using Unity to manage the lifetime of a custom user class instance. I am planning on extending the LifetimeManager with a custom ASP.NET session manager. What I want to be able to do is store and retrieve the currently logged in user object from my custom classes, and have Unity get the instance of User from the session object in ASP.NET, or (when in a Win32 project) retrieve it statically or from the current thread.

So far my best solution is to create a static instance of my Unity container on startup, and use the Resolve method to get my User object from each of my classes. However, this seems to create a dependency on the unity container in my other classes. What is the more "Unity" way of accomplishing this goal? I would like to be able to read/replace the current User instance from any class.

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about unity