title: nhibernate webforms with class library
body: <p>I am very new to NHibernate, and am little confused on where features should live.</p>
  
  <p>I have the following solution</p>
  
  <p>1) MyProject.Web (web forms application)</p>
  
  <p>2) MyProject.Domain (class library)  </p>
  
  <ul>
  <li>nhibernate.config</li>
  <li>product.hbm.xml</li>
  </ul>
  
  <p><em>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 )</em> </p>
  
  <p><em>Where should the connectionString live?</em></p>
  
  <p><strong>HTTPModule in web forms application</strong></p>
  
  <pre><code> 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();
  }
  </code></pre>
  
  <p><strong>nhibernate.config</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"&gt;
      &lt;session-factory name="RBL.Domain"&gt;
          &lt;property name="dialect"&gt;NHibernate.Dialect.MsSql2005Dialect&lt;/property&gt;  
          &lt;property name="connection.provider"&gt;NHibernate.Connection.DriverConnectionProvider&lt;/property&gt;
          &lt;property name="connection.driver_class"&gt;NHibernate.Driver.SqlClientDriver&lt;/property&gt;
          &lt;property name="adonet.batch_size"&gt;16&lt;/property&gt;
          &lt;property name="current_session_context_class"&gt;web&lt;/property&gt;
          &lt;property name="proxyfactory.factory_class"&gt;NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle&lt;/property&gt;
          &lt;mapping assembly="RBL.Domain"/&gt;
      &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>