public class NHManager{ public NHManager() { //load config //create session factory }}
public abstract class BusinessBase{ private static NHManager _mgr = null; [ThreadStatic()] protected static NHManager Manager { get { if( _mgr == null) _mgr = new NHManager(); return _mgr; } } private ISession _session = null; protected ISession CurrentSession { get { if( _session == null ) { //see if context contains it if( HttpContext.Current[NHSESSION] == null ) //key is a constant { //this is the first access for this request, //load the object _session = Manager.OpenSession(); HttpContext.Current[NHSESSION] = _session; } else { //it exists in this request _session = HttpContext.Current[NHSESSION] as ISession; } } //make sure it's connected if(! _session.IsConnected) _session.ReConnect(); return _session; } }}
I'm Ben Scheirman. I am a .NET software developer with a strong interest in agility. I work as a Principal Consultant with Sogeti.
Read more here.
email me
Ads by The Lounge
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.