Using FluentNHibernate in a web application, I've created a singleton SessionFactory class to have the ability of the following:
SessionFactory.Instance //returns ISessionFactory
Is it common/best practice to open/close sessions as follows?
using(ISession session = SessionFactory.Instance.OpenSession())
{
using(ITransaction transaction = session.BeginTransaction())
{
//some operation
}
}
The above code would live in the respective repository classes for a given entity.
I've noticed there is a theme of creating a HttpModule to open the session at the start and stop of the application, but I'm wondering if this is situational or more common.
UPDATE
Going forward with the HttpModule, I have a similar thought:
With a repository class, I'm basically doing the following(config uses WebSessionContext):
using(ISession session = SessionFactory.Instance.GetCurrentSession())
{
using(ITransaction transaction = session.BeginTransaction())
{
//some operation
}
}