Nhibernate的Session如果每次都打开,关闭一次会很麻烦,如果忘记关闭Session,很容易就达到连接池的最大值,我们可以把他移动到实现IHttpModule的类中
在请求开始时初始化CoreRepository,并且放入每次请求缓存(HttpContent.Item)中
参考Cuyahoga的实现
在Web.config
中注册Module
调用方法:
通常可以放到构造函数中
_coreRepository = HttpContext.Current.Items["CoreRepository"] as CoreRepository;
可以参考:
操作Nhibernate