Will Ninject call dispose and close the NHibernate Isession?

蓝咒 提交于 2019-12-03 13:04:38

If I understand the code correctly the answer is yes. One of the ActivationStrategies used by Ninject is the DisposableStrategy, whose Deactivate method, calls Dispose on anything that implements IDisposable. If you're using the Ninject.Web.MVC extensions, the OnePerRequestModule will automatically clear the binding cache. This will call the Deactivate method on all the ActivationStrategies including the DisposableStrategy.

Since ISession implements IDisposable, it will be disposed. The default implementation of ISession, SessionImpl, closes the Session on Dispose.

If you're not using the Ninject.Web.MVC extensions the Cache will eventually be cleared, but may not happen right at EndRequest.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!