开发者

Configure Castle Windsor Container and Nhibernate using Nhibernate Facility

开发者 https://www.devze.com 2023-02-10 18:02 出处:网络
I\'m trying to configure Nhibernate with Castle Windsor Container using Nhibernate Facility. But i\'m having

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.NH开发者_Python百科ibernateIntegration.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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消