using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Web; using NHibernate; using ProductModel.Session; namespace ProductModel { //See http://www.codeproject.com/KB/architecture/NHibernateBestPractices.aspx#WEB public class SessionModule : IHttpModule { private ISession _session; public void Init(HttpApplication context) { context.BeginRequest += new EventHandler(BeginTransaction); context.EndRequest += new EventHandler(CloseSession); } private void CloseSession(object sender, EventArgs e) { SessionManager.CloseSession(); } //Create our session private void BeginTransaction(object sender, EventArgs e) { _session = SessionManager.GetCurrentSession(); } public void Dispose() { _session = null; } } }