示例#1
0
        protected NHibernateTransactionScope(IsolationLevel isolationLevel, INHibernateConfigurationProvider nHibernateConfigurationProvider, bool newSessionRequired)
        {
            isAlreadyDisposed = false;

            //Create session if no current scope exists or if explicitly requested)
            if (currentScope == null || newSessionRequired)
            {
                nHibernateSession = GetSessionFactory(nHibernateConfigurationProvider).OpenSession();
            }

            transaction = Session.BeginTransaction(isolationLevel);

            //Update current scope
            previousScope = currentScope;
            currentScope  = this;
        }
示例#2
0
        protected virtual void Dispose(bool isDisposing)
        {
            if (!isAlreadyDisposed)
            {
                isAlreadyDisposed = true;

                if (isDisposing)
                {
                    try
                    {
                        if (nHibernateSession != null)
                        {
                            nHibernateSession.Dispose();
                        }
                    }
                    catch (Exception ex)
                    {
                        Loggers.ApplicationLogger.Error(ex.Message, ex);
                        throw;
                    }
                    finally
                    {
                        currentScope = previousScope;
                        try
                        {
                            transaction.Dispose();
                        }
                        catch (Exception ex)
                        {
                            Loggers.ApplicationLogger.Error(ex.Message, ex);
                            throw;
                        }
                    }
                }

                GC.SuppressFinalize(this);
            }
        }