Using ASP.NET Session for Lifetime Management (Unity)

前端 未结 7 2102
猫巷女王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

    Why not use the cache object instead...then you can use it both from win and web. Like this:

        IUnityContainer container= HttpRuntime.Cache.Get("Unity") as IUnityContainer;
    
        if (container == null)
        {
            container= // init container
    
            HttpRuntime.Cache.Add("Unity",
                container,
                null,
                Cache.NoAbsoluteExpiration,
                Cache.NoSlidingExpiration,
                CacheItemPriority.NotRemovable,
                null);
        }
    
        // return container or something
    

    HttpRuntime.Cache will work both in win and web

提交回复
热议问题