Nhibernate的Session如果每次都打开,关闭一次会很麻烦,如果忘记关闭Session,很容易就达到连接池的最大值,我们可以把他移动到实现IHttpModule的类中
在请求开始时初始化CoreRepository,并且放入每次请求缓存(HttpContent.Item)中
参考Cuyahoga的实现

通过实现IHttpModule初始化Nhibernate的Sessionusing System;
通过实现IHttpModule初始化Nhibernate的Session
using System.Web;
通过实现IHttpModule初始化Nhibernate的Session
通过实现IHttpModule初始化Nhibernate的Session
using VirtualBank.Service;
通过实现IHttpModule初始化Nhibernate的Session
通过实现IHttpModule初始化Nhibernate的Session
namespace VirtualBank.Web.HttpModules

在Web.config
中注册Module
通过实现IHttpModule初始化Nhibernate的Session<httpModules>
通过实现IHttpModule初始化Nhibernate的Session        
<add type="VirtualBank.Web.HttpModules.NHSessionModule, VirtualBank" name="NHSessionModule" />
通过实现IHttpModule初始化Nhibernate的Session        
</httpModules>

调用方法:
通常可以放到构造函数中
_coreRepository = HttpContext.Current.Items["CoreRepository"] as CoreRepository;
可以参考:
操作Nhibernate

相关文章:

  • 2022-12-23
  • 2021-08-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-08
  • 2021-01-24
  • 2021-12-02
猜你喜欢
  • 2021-09-01
  • 2021-11-19
  • 2021-12-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-12
相关资源
相似解决方案