Exemple #1
0
        public DbConnectionScope BeginNested()
        {
            var scope = DbScopeConfig.CreateConnectionScope(GetType()) as DbConnectionScope;

            scope._rootScope   = this;
            scope._isRootScope = false;
            return(scope);
        }
Exemple #2
0
        /// <summary>
        ///     Create new instance of <paramref name="dbConnectionScopeType"/> using a registered factory or a parameterless constructor.
        ///     If <paramref name="transaction"/> is provided then a nested <see cref="DbConnectionScope"/> is returned.
        /// </summary>
        /// <param name="dbConnectionScopeType"></param>
        /// <param name="transaction"></param>
        /// <exception cref="ArgumentNullException">
        ///     If <paramref name="dbConnectionScopeType"/> is null.
        /// </exception>
        /// <exception cref="MissingMethodException">
        ///     If no factory have been registered for <paramref name="dbConnectionScopeType"/> and it has no parameterless constructor.
        /// </exception>
        public DbConnectionScope CreateConnectionScope(Type dbConnectionScopeType, IDbTransactionScope transaction = null)
        {
            if (dbConnectionScopeType == null)
            {
                throw new ArgumentNullException(nameof(dbConnectionScopeType));
            }

            if (transaction == null)
            {
                return(DbScopeConfig.CreateConnectionScope(dbConnectionScopeType));
            }
            else
            {
                return(transaction.GetConnectionScope(dbConnectionScopeType).BeginNested());
            }
        }
Exemple #3
0
        public DbConnectionScope GetConnectionScope(Type dbConnectionScopeType)
        {
            if (dbConnectionScopeType == null)
            {
                throw new ArgumentNullException(nameof(dbConnectionScopeType));
            }
            ThrowIfHandled();

            if (!_dbConnectionScopeCache.ContainsKey(dbConnectionScopeType))
            {
                // First time we've been asked for this particular DbScope type, create one and cache it.
                var scope = DbScopeConfig.CreateConnectionScope(dbConnectionScopeType);
                scope.CurrentTransactionScope = this;
                AddConnectionScopeEnlistment(scope, true);
            }

            return(_dbConnectionScopeCache[dbConnectionScopeType].Scope);
        }