使用 Nhibernate 工具配置 Castle Windsor 容器和 Nhibernate

发布于 2024-10-17 05:02:27 字数 3048 浏览 5 评论 0原文

我正在尝试使用 Nhibernate 设施通过 Castle Windsor Container 配置 Nhibernate。但我有

这是我的 web.config

<castle>
    <facilities>
      <facility id="nhibernate" 
                type="Castle.Facilities.NHibernateIntegration.NHibernateFacility, Castle.Facilities.NHibernateIntegration"                
                isWeb="true">
        <factory id="nhibernate.factory">
          <settings>
            <item key="connection.provider">NHibernate.Connection.DriverConnectionProvider</item>
            <item key="connection.driver_class">NHibernate.Driver.SqlClientDriver</item>
            <item key="connection.connection_string">Data Source=184.106.114.146\calyx;Initial Catalog=ClaimBook;User ID=system;Password=Manager1!;Persist Security Info=True;Max Pool Size=120;Connection Lifetime=120;</item>
            <item key="dialect">NHibernate.Dialect.MsSql2000Dialect</item>
            <item key="show_sql">true</item>
            <item key="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</item>
          </settings>
          <resources>            
            <resource assembly="Astute.Framework.Data" />
          </resources>
        </factory>
      </facility>
    </facilities>
  </castle>

并在我的 global.asax 中添加到以下行

container.Kernel.Register(Component.For<ISessionManager>().ImplementedBy<DefaultSessionManager>().Named("nhfacility.sessionmanager"));
            container.Kernel.Register(Component.For<ISessionFactoryResolver>().ImplementedBy<SessionFactoryResolver>().Named("nhfacility.sessionfactory.resolver"));
            container.Kernel.Register(Component.For<ISessionStore>().ImplementedBy<WebSessionStore>().Named("nhfacility.sessionstore"));
            container.Kernel.Register(Component.For<ITransactionManager>().ImplementedBy<DefaultTransactionManager>().Named("nhibernate.transaction.manager"));

但我收到以下错误

*ISessionFactory 组件未映射到指定的别名:nh.facility .default 堆栈跟踪: [FacilityException:未为指定别名映射 ISessionFactory 组件:nh.facility.default] Castle.Facilities.NHibernateIntegration.Internal.SessionFactoryResolver.GetSessionFactory(字符串别名)+147 Castle.Facilities.NHibernateIntegration.DefaultSessionManager.CreateSession(字符串别名)+65 Castle.Facilities.NHibernateIntegration.DefaultSessionManager.OpenSession(字符串别名)+150 Castle.Facilities.NHibernateIntegration.DefaultSessionManager.OpenSession() +37 Castle.Facilities.NHibernateIntegration.Components.Web.SessionWebModule.OnBeginRequest(对象发送者,EventArgs e)+124 System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +148 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& CompletedSynchronously) +75*

我不知道配置中缺少什么。有什么想法吗?

谢谢伊姆兰

I'm trying to configure Nhibernate with Castle Windsor Container using Nhibernate Facility. But i'm having

Here is my web.config

<castle>
    <facilities>
      <facility id="nhibernate" 
                type="Castle.Facilities.NHibernateIntegration.NHibernateFacility, Castle.Facilities.NHibernateIntegration"                
                isWeb="true">
        <factory id="nhibernate.factory">
          <settings>
            <item key="connection.provider">NHibernate.Connection.DriverConnectionProvider</item>
            <item key="connection.driver_class">NHibernate.Driver.SqlClientDriver</item>
            <item key="connection.connection_string">Data Source=184.106.114.146\calyx;Initial Catalog=ClaimBook;User ID=system;Password=Manager1!;Persist Security Info=True;Max Pool Size=120;Connection Lifetime=120;</item>
            <item key="dialect">NHibernate.Dialect.MsSql2000Dialect</item>
            <item key="show_sql">true</item>
            <item key="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</item>
          </settings>
          <resources>            
            <resource assembly="Astute.Framework.Data" />
          </resources>
        </factory>
      </facility>
    </facilities>
  </castle>

and in my global.asax I added to following lines

container.Kernel.Register(Component.For<ISessionManager>().ImplementedBy<DefaultSessionManager>().Named("nhfacility.sessionmanager"));
            container.Kernel.Register(Component.For<ISessionFactoryResolver>().ImplementedBy<SessionFactoryResolver>().Named("nhfacility.sessionfactory.resolver"));
            container.Kernel.Register(Component.For<ISessionStore>().ImplementedBy<WebSessionStore>().Named("nhfacility.sessionstore"));
            container.Kernel.Register(Component.For<ITransactionManager>().ImplementedBy<DefaultTransactionManager>().Named("nhibernate.transaction.manager"));

But i'm getting following error

*An ISessionFactory component was not mapped for the specified alias: nh.facility.default
Stack Trace:
[FacilityException: An ISessionFactory component was not mapped for the specified alias: nh.facility.default]
Castle.Facilities.NHibernateIntegration.Internal.SessionFactoryResolver.GetSessionFactory(String alias) +147
Castle.Facilities.NHibernateIntegration.DefaultSessionManager.CreateSession(String alias) +65
Castle.Facilities.NHibernateIntegration.DefaultSessionManager.OpenSession(String alias) +150
Castle.Facilities.NHibernateIntegration.DefaultSessionManager.OpenSession() +37
Castle.Facilities.NHibernateIntegration.Components.Web.SessionWebModule.OnBeginRequest(Object sender, EventArgs e) +124
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +148
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75*

I don't know what i'm missing in configuration. Any thoughts?

Thanks

Imran

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

多情出卖 2024-10-24 05:02:27

ISessionManagerISessionFactoryResolver 等是由 NHibernate 工具管理的组件。您不应该手动注册它们。

您可以通过执行以下操作从该 web.config 安装该工具:

container.Install(Configuration.FromAppConfig());

有关详细信息,请参阅 参考文档关于配置安装程序

ISessionManager, ISessionFactoryResolver, etc are components managed by the NHibernate facility. You're not supposed to register them manually.

You can install the facility from that web.config by doing:

container.Install(Configuration.FromAppConfig());

For more information, see the reference docs about Configuration installers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文