Using ASP.NET Session for Lifetime Management (Unity)

前端 未结 7 2086
猫巷女王i
猫巷女王i 2020-12-10 11:59

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.

相关标签:
7条回答
  • 2020-12-10 12:35

    If by "a custom ASP.NET session manager" you are talking about an NHibernate Session or a Data/ObjectContext, it sounds like what you need is an IUserRepository injected into either the constructor or property setter from which you could retrieve the User object. The implementation of IUserRepository could be anything from database access to a backend cache, etc. If you are using .Resolve() on the container directly, you are following the Service Locator pattern and not properly using Unity for all that it can provide.

    You can then use Ravi's answer to manage the lifetime of the repository.

    0 讨论(0)
提交回复
热议问题