/// <summary>
        /// Retursn the NHibernate session to use
        /// </summary>
        /// <returns></returns>
        internal ISession GetNHibernateSession(bool isReadonly, bool forceNewUnbounded = false)
        {
            //if a session has been supplied via the constructor (i.e. for testing)
            if (SingleProvidedSession != null)
            {
                if (!IsSingleSessionFinalized)
                {
                    using (new WriteLockDisposable(Locker))
                    {
                        IsSingleSessionFinalized = true;
                        //add the session to the finalizer
                        FrameworkContext.ScopedFinalizer.AddFinalizerToScope(SingleProvidedSession, x => UnbindAndCloseSession(NhSessionFactory));
                    }
                }


                EnsureFlushMode(SingleProvidedSession as ISessionImplementor, isReadonly);

                return(CheckFirstRunTasks(SingleProvidedSession));
            }


            // See http://nhforge.org/doc/nh/en/index.html#architecture-current-session
            // for details on contextual sessions

            var sessionFactory = GetNHibernateSessionFactory();

            if (!forceNewUnbounded)
            {
                //if we have a session factory, then check if its bound
                if (sessionFactory != null && CurrentSessionContext.HasBind(sessionFactory))
                {
                    LogHelper.TraceIfEnabled <EntityRepositoryFactory>("GetNHibernateSession: using ISessionFactory.GetCurrentSession()");
                    var boundSession = NhSessionFactory.GetCurrentSession();

                    EnsureFlushMode(boundSession as ISessionImplementor, isReadonly);

                    return(CheckFirstRunTasks(boundSession));
                }
            }

            LogHelper.TraceIfEnabled <EntityRepositoryFactory>("GetNHibernateSession: using ISessionFactory.OpenSession()");

            var sessionToReturn = NhSessionFactory.OpenSession();

            EnsureFlushMode(sessionToReturn as ISessionImplementor, isReadonly);

            //add the new session to the finalizer
            FrameworkContext.ScopedFinalizer.AddFinalizerToScope(sessionToReturn, x => UnbindAndCloseSession(NhSessionFactory));

            if (!forceNewUnbounded)
            {
                //dont bind the session if we're forcing new for nested transactions
                CurrentSessionContext.Bind(sessionToReturn);
            }


            return(CheckFirstRunTasks(sessionToReturn));
        }
 public SettingController()
 {
     _session     = NhSessionFactory.OpenSession();
     _userService = new UserService(_session);
     _menuService = new MenuService(_session);
 }
 public RoomBookingController()
 {
     _session = NhSessionFactory.OpenSession();
     _hotelReservationService = new HotelReservationService(_session);
 }
 public AccountController()
 {
     _session     = NhSessionFactory.OpenSession();
     _userService = new UserService(_session);
 }