tags:

views:

76

answers:

1

I am very new to NHibernate, and am little confused on where features should live.

I have the following solution

1) MyProject.Web (web forms application)

2) MyProject.Domain (class library)

  • nhibernate.config
  • product.hbm.xml

So is it correct I should put the following method in a IHttpModule? ( i can't use a global asax as it's use by the CMS i'm running )

Where should the connectionString live?

HTTPModule in web forms application

 private static ISessionFactory CreateSessionFactory()
 {
     var cfg = new Configuration().Configure(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "nhibernate.config"));
     cfg.SetProperty(NHibernate.Cfg.Environment.ConnectionStringName, System.Environment.MachineName);
     NHibernateProfiler.Initialize();

     return cfg.BuildSessionFactory();
}

nhibernate.config

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory name="RBL.Domain">
        <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>  
        <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
        <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
        <property name="adonet.batch_size">16</property>
        <property name="current_session_context_class">web</property>
        <property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
        <mapping assembly="RBL.Domain"/>
    </session-factory>
</hibernate-configuration>
A: 

The connectionString should live in either your hibernate.cfg.xml file or your web.config file...

A great place to guide you through starting is the Your first Nhibernate based application from the NHForge wikis...certainly helped me when I was figuring it out (still helps me!)...as you seem to have a whole host of questions relating to getting started.

davidsleeps