加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – Windsor NHibernate ISession MVC

发布时间:2020-12-16 03:57:04 所属栏目:asp.Net 来源:网络整理
导读:我试图让Windsor为每个请求提供一个实例ISession,应该将其注入所有存储库 这是我的容器设置 container.AddFacilityFactorySupportFacility().Register( Component.ForISessionFactory().Instance(NHibernateHelper.GetSessionFactory()).LifeStyle.Singleton
我试图让Windsor为每个请求提供一个实例ISession,应该将其注入所有存储库

这是我的容器设置

container.AddFacility<FactorySupportFacility>().Register(
    Component.For<ISessionFactory>().Instance(NHibernateHelper.GetSessionFactory()).LifeStyle.Singleton,Component.For<ISession>().LifeStyle.Transient
        .UsingFactoryMethod(kernel => kernel.Resolve<ISessionFactory>().OpenSession())
    );

//add to the container
container.Register(
    Component.For<IActionInvoker>().ImplementedBy<WindsorActionInvoker>(),Component.For(typeof(IRepository<>)).ImplementedBy(typeof(NHibernateRepository<>))
    );

它基于这里的StructureMap帖子
http://www.kevinwilliampang.com/2010/04/06/setting-up-asp-net-mvc-with-fluent-nhibernate-and-structuremap/

但是,当运行它时,也会为它注入的每个对象创建一个新的Session.我错过了什么?

(仅供参考NHibernateHelper,为Nhib设置配置)

解决方法

ISession应该有LifeStyle.PerWebRequest.但你可以使用 NHibernate facility而不是手动处理这些东西.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读