Beispiel #1
0
        /// <summary>
        /// Shut down this instance.
        /// Disposes all connections it holds and restores the prior scope.
        /// </summary>
        public void Dispose()
        {
            if (_disposed)
            {
                return;
            }

            if (Current == null || Current == this)
            {
                DbConnectionScope prior = _priorScope;
                while (prior != null && prior._disposed)
                {
                    prior = prior._priorScope;
                }

                _currentScope.Value = prior;
            }

            if (_connections != null)
            {
                foreach (var connection in _connections.Values)
                {
                    connection.Dispose();
                }
            }
            _disposed = true;
        }
Beispiel #2
0
 /// <summary>
 /// Constructor with options
 /// </summary>
 /// <param name="option"></param>
 public DbConnectionScope(DbConnectionScopeOption option)
 {
     if (option == DbConnectionScopeOption.Suppress)
     {
         _priorScope         = _currentScope.Value;
         _currentScope.Value = null;
     }
     else if (option == DbConnectionScopeOption.RequiresNew ||
              (option == DbConnectionScopeOption.Required && _currentScope.Value == null))
     {
         _connections        = new Dictionary <string, DbConnection>();
         _priorScope         = _currentScope.Value;
         _currentScope.Value = this;
     }
     _disposed = false;
 }
 public LocalTransactionScope(TransactionScopeOption scopeOption, TransactionOptions transactionOptions)
 {
     _transactionScope = new TransactionScope(scopeOption, transactionOptions, TransactionScopeAsyncFlowOption.Enabled);
     _connectionScope  = new DbConnectionScope(ToDbConnectionScopeOption(scopeOption));
 }