public ChildTransactionScope( PrimaryTransactionScope primaryTransactionScope ) { _primaryTransactionScope = primaryTransactionScope; _innerScope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled); }
internal void DeregisterTransaction(PrimaryTransactionScope scope) { if (scope == null) { throw new ArgumentNullException(nameof(scope)); } var scopeToRemoveKey = _primaryTransactionScopes .Where(s => s.Value == scope) .Select(s => (int?)s.Key) .SingleOrDefault(); if (scopeToRemoveKey.HasValue) { _primaryTransactionScopes.Remove(scopeToRemoveKey.Value); } }
/// <summary> /// Creates a new transaction scope associated with the specified connection. /// The scope can be nested inside another scope in which case the underlying /// db transaction is only committed once both the outer and inner transaction(s) /// have been committed. The returned ITransactionScope implements IDisposable /// and should be wrapped in a using statement. /// </summary> /// <param name="dbConnection"> /// <para> /// The DbConnection instance to manage transactions for. Transaction scopes /// created by this instance only apply to a single DbConnection, so if you want /// the scope to span additional data access mechanism then they must share the /// same connection. /// </para> /// <para> /// You can use the ICofoundryDbConnectionManager to get a reference to the shared /// connection directly. /// </para> /// </param> /// <returns>ITransactionScope, which is IDisposable and must be disposed.</returns> public ITransactionScope Create(DbConnection dbConnection) { ITransactionScope scope; var connectionHash = dbConnection.GetHashCode(); var primaryScope = _primaryTransactionScopes.GetOrDefault(connectionHash); if (primaryScope == null) { primaryScope = new PrimaryTransactionScope(this); _primaryTransactionScopes.Add(connectionHash, primaryScope); scope = primaryScope; } else { scope = new ChildTransactionScope(primaryScope); } return(scope); }