Exemple #1
0
        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));
            };
        }
Exemple #2
0
 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;
 }
Exemple #3
0
 protected UnitOfWorkBase(ILogger Logger, ICorrelationIdAccessor CorrelationIdAccessor, ILoggedDatabase Database)
 {
     this.Logger   = Logger;
     CorrelationId = CorrelationIdAccessor.GetCorrelationId();
     _database     = Database;
 }