Click here to Skip to main content
15,891,976 members
Articles / Web Development / ASP.NET

NHibernate Best Practices with ASP.NET, 1.2nd Ed.

Rate me:
Please Sign up or sign in to vote.
4.96/5 (322 votes)
11 Jun 2008CPOL60 min read 8.6M   35.9K   1.1K  
This article describes best practices for leveraging the benefits of NHibernate 1.2, ASP.NET, generics and unit testing together.
<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="castle"
			type="Castle.Windsor.Configuration.AppDomain.CastleSectionHandler, Castle.Windsor" />
    <section name="log4net"
		    type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
    <section name="nhibernateSettings"
		    type="ProjectBase.Data.OpenSessionInViewSection, ProjectBase.Data" />
  </configSections>

  <nhibernateSettings>
    <!-- List every session factory that will be needed; transaction management and closing sessions 
		will be managed with the open-session-in-view module -->
    <sessionFactories>
      <clearFactories />
      <sessionFactory name="northwind" factoryConfigPath="C:\My Stuff\Dev\RandD\NHibernate\Article\Edition1.2\EnterpriseSample\EnterpriseSample.Web\Config\NorthwindNHibernate.config" isTransactional="true" />
    </sessionFactories>
  </nhibernateSettings>

  <castle>
    <include uri="file://Config/CastleComponents.config" />
  </castle>

  <!-- If you want to turn it off completely, include threshold="OFF" below -->
  <log4net>
    <appender name="LogAllToFile" type="log4net.Appender.FileAppender">
      <file value="EnterpriseSample.log"/>
      <appendToFile value="false"/>
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%d [%t] %-5l - %m%n%n"/>
      </layout>
    </appender>
    <root>
      <priority value="ALL"/>
      <!-- ALL, DEBUG, INFO, WARN, ERROR, FATAL, OFF-->
      <appender-ref ref="LogAllToFile"/>
    </root>
  </log4net>

  <!-- Compatible with IIS 6 -->
  <system.web> 
    <compilation debug="true" />
		<httpModules>
      <add name="ErrorModule" type="ProjectBase.Utils.Web.ErrorModule, ProjectBase.Utils"/>
      <add name="NHibernateSessionModule" type="ProjectBase.Data.NHibernateSessionModule, ProjectBase.Data"/>
    </httpModules>
	</system.web>

  <!-- Compatible with IIS 7 -->
  <!--
  <system.webServer>
    <modules>
      <add name="ErrorModule" type="ProjectBase.Utils.Web.ErrorModule, ProjectBase.Utils" preCondition="managedHandler" />
      <add name="NHibernateSessionModule" type="ProjectBase.Data.NHibernateSessionModule, ProjectBase.Data" preCondition="managedHandler" />
    </modules>
    <validation validateIntegratedModeConfiguration="false" />
  </system.webServer>
  -->
</configuration>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions