1

我正在尝试使用 Nhibernate Facility 使用 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 *

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

谢谢

伊姆兰

4

1 回答 1

3

ISessionManager, ISessionFactoryResolver, 等是由 NHibernate 设施管理的组件。您不应该手动注册它们。

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

container.Install(Configuration.FromAppConfig());

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

于 2011-02-15T15:18:51.710 回答