O'Reilly logo

NHibernate 3.0 Cookbook by Jason Dentler

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a session ASP.NET MVC action filter

Often, a unit of work maps neatly on to a single controller action. I'll show you how to create an action filter to manage our NHibernate sessions in an ASP.NET MVC application.

Getting ready

Setup an ASP.NET MVC application for NHibernate. The steps are as follows:

  1. Create a new ASP.NET MVC application.
  2. Add references to NHibernate.dll, NHibernate.ByteCode.Castle.dll, log4net.dll, and our Eg.Core project from Chapter 1.
  3. In the web.config file, set up the NHibernate and log4net configuration sections. Refer to the Configuring NHibernate with App.config recipes in Chapter 2.
  4. Set the current_session_context_class property to web.
  5. In Global.asax, create a static property named SessionFactory.
    public static ISessionFactory ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required