Hi,
In my ASP.net website, I have a static class that is responsible for handling my NHibernate ISession(s). The heart of it is:
Code:
public abstract class Helper
{
private static ISession _current;
public static ISession GetSession()
{
if (_current == null)
_current = GetNewSession();
return _current;
}
public static ISession GetNewSession()
{
NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();
cfg.AddAssembly("DAL");
ISessionFactory factory = cfg.BuildSessionFactory();
_current = factory.OpenSession();
return _current;
}
}
}
If I understand what I did correctly, then my code attempts to maintain a single ISession across the entire application lifespan.
I am concerned - Is this a good strategy for an ASP.net website? If not - what other strategy would you recommened? One Session per one Request?
Thanks!
urig