1
votes

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

1
why are you manually registering ISessionManager et al? The facility takes care of that.Mauricio Scheffer
I was surprise as well why do i need to register manually. It should be handle by facility. May be i'm missing some configuration. I have followed the steps described on the this URL stw.castleproject.org/%28S%28ta5wga45q0nwdif0d3vk0saf%29%29/…. I'm sure i'm doing something wrong in Global.asax. any idea?user585014
Do you have any idea how can I register the nhibernate facility. I didn't get any example.user585014
Nowhere in the wiki does it says that you have to manually register ISessionManagerMauricio Scheffer
but if you look at the following URL castleproject.org/container/facilities/trunk/nhibernate/… it says To use the NHibernate facility you just need to register it and provide the configuration. If you want to use the integration level 2 approach, you can make your data access component require the ISessionManager.user585014

1 Answers

3
votes

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.