Thanks for helping everyone. A little more research led me to the NHibernate Burrow project.
From the FAQ project ( http://nhforge.org/wikis/burrow/faq.aspx ):
Burrow is a lightweight middleware designed to support .Net applications using NHibernate (possibly also referred to as NH in this article) as an ORM framework. Using Asp.net with NHibernate can be a problem because NHibernate is a stateful environment, while Asp.net is a stateless system. Burrow can help resolve this conflict by providing advanced and intelligent session / transaction management and others.
I had to jump over several hoops to make it work in my project. Since the current version uses the old version of NHibernate, I had to download the latest source from an external line, open it in VS, add links to the latest version of NHibernate and recompile (fortunately, no errors).
I tested NHibernate Burrow in several ways.
1) Keep typing ISession in my repositories
To do this, I had to add links to NHibernate, NHibernate.Burrow and NHibernate.Burrow.WebUtil in my MVC project.
In web.config, I had to install Burrow (see http://nhforge.org/wikis/burrow/get-started.aspx ), and then add the following to my StructureMap registry:
For<ISession>() .TheDefault.Is .ConstructedBy(x => new NHibernate.Burrow.BurrowFramework().GetSession());
I like this approach, as it means that my repositories (or controllers) are not related to Burrow. I donβt really like the fact that I have to reference these three assemblies in my web project, but at least I lose the session management code - all this is handled by Burrow.
2) A second approach would be to install ISession in my repository constructors as follows:
public ProductRepository() : this(new BurrowFramework().GetSession()) { } public ProductRepository(ISession session) { _session = session; }
I can still override ISession to check my repositories. I then have a direct dependence on Burrow, but perhaps this is not so bad?
On the plus side, the only build I need to reference from my web project is NHibernate.Burrow.WebUtils.
Interest in which of the two people will go and why.