Inheritance: ICurrentSessionContext
Exemplo n.º 1
0
        private void ApplicationBeginRequest(object sender, EventArgs e)
        {
            if (Container == null)
            {
                return;
            }

            var sessionFactory = Container.Resolve <ISessionFactory>();

            LazySessionContext.Bind(sessionFactory);
        }
Exemplo n.º 2
0
        private void ApplicationEndRequest(object sender, EventArgs e)
        {
            if (Container == null)
            {
                return;
            }

            var sessionFactory = Container.Resolve <ISessionFactory>();
            var session        = LazySessionContext.UnBind(sessionFactory);

            if (session == null)
            {
                // session was not accessed during this request
                return;
            }

            var tx = session.Transaction;

            if (tx != null)
            {
                if (tx.IsActive)
                {
                    try
                    {
                        tx.Commit();
                    }
                    catch (Exception)
                    {
                        tx.Rollback();
                        throw;
                    }
                }
            }
            else
            {
                session.Flush();
            }
            session.Close();
        }