Inheritance: ICurrentSessionContext
コード例 #1
0
        private void ApplicationBeginRequest(object sender, EventArgs e)
        {
            if (Container == null)
            {
                return;
            }

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

            LazySessionContext.Bind(sessionFactory);
        }
コード例 #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();
        }