public IDbTransaction BeginTransaction(IsolationLevel isolationLevel = IsolationLevel.ReadCommitted) { try { _semaphore.Wait(); if (CurrentTransaction != null) { throw new InvalidOperationException("Transaction already in progress!"); } CurrentTransaction = new DbTransactionWrapper() .WithIsolationLevel(isolationLevel) .WithOnDispose(() => CurrentTransaction = null); return(CurrentTransaction); } finally { _semaphore.Release(); } }
public void Dispose() { CurrentTransaction?.Dispose(); CurrentTransaction = null; _semaphore?.Dispose(); }