protected RepositoryBase(ILogger Logger, ICorrelationIdAccessor CorrelationIdAccessor, ILoggedDatabase Database) { this.Logger = Logger; CorrelationId = CorrelationIdAccessor.GetCorrelationId(); _database = Database; GetContextAsync = async() => { // Return a new, unshared database connection. // Unit of Work classes should modify this Func to return a shared (by multiple repositories) database connection. var connection = await _database.OpenConnectionAsync(CorrelationId); var transaction = connection.BeginTransaction(); return(new RepositoryContext(connection, transaction, true, true)); }; }
protected virtual void Dispose(bool Disposing) { if (_disposed) { return; } if (!_committed) { // Rollback uncommitted transaction. _transaction?.TryRollback(); } if (Disposing) { // Release managed objects. _database = null; } // Release unmanaged objects. _transaction?.Dispose(); _transaction = null; _dbConnection?.Dispose(); _dbConnection = null; // Do not release logger. Its lifetime is controlled by caller. _disposed = true; }
protected UnitOfWorkBase(ILogger Logger, ICorrelationIdAccessor CorrelationIdAccessor, ILoggedDatabase Database) { this.Logger = Logger; CorrelationId = CorrelationIdAccessor.GetCorrelationId(); _database = Database; }