Exemplo n.º 1
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;
 }
Exemplo n.º 2
0
        public DbConnectionScope(DbConnectionScopeOption option)
        {
            _isDisposed      = true; // short circuit Dispose until we're properly set up
            this._transId    = CurrentTransactionId;
            this._option     = option;
            this._outerScope = null;

            DbConnectionScope outerScope = _currentScope;
            bool isAllocateOk            = (outerScope == null || outerScope._transId != this._transId);

            if (option == DbConnectionScopeOption.RequiresNew ||
                (option == DbConnectionScopeOption.Required && isAllocateOk))
            {
                // only bother allocating dictionary if we're going to push
                _connections = new Lazy <ConcurrentDictionary <string, DbConnection> >(() => new ConcurrentDictionary <string, DbConnection>(), true);

                // Devnote:  Order of initial assignment is important in cases of failure!
                _outerScope   = outerScope;
                _isDisposed   = false;
                _currentScope = this;
            }
        }