What should UnityContainer.Teardown method do?

前端 未结 1 1326
挽巷
挽巷 2021-01-18 12:57

I would like to explicitly \"release\" object instance resolved by Unity. I hoped the Teardown method should be used exactly for this so I tried something like this:

相关标签:
1条回答
  • 2021-01-18 13:32

    Unity TearDown doesn't do anything out of the box. You do not need to remove from HttpContext.Current.Items as it will be cleared automatically at the end of the request. What you may want to do is call Dispose on any IDisposable object stored there. You would do this from EndRequest in Global.asax:

    foreach (var item in HttpContext.Current.Items.Values)
                {
                    var disposableItem = item as IDisposable;
    
                    if (disposableItem != null)
                    {
                        disposableItem.Dispose();
                    }
                }
    
    0 讨论(0)
提交回复
热议问题