public virtual void AddDatabase([NotNull] Type type, [NotNull] IDatabase database) { if (_databases.ContainsKey(type)) { throw new InfrastructureException("There is already a database API in this unit of work with given type: " + type.Name); } if (database is ISupportTransaction databaseSupportTransaction && databaseSupportTransaction.CurrentTransaction != null) { if (_currentTransaction == null) { _currentTransaction = new UnitOfWorkTransaction(); } _currentTransaction.ChildrenTransactions.Add(databaseSupportTransaction.CurrentTransaction); } _databases.Add(type, database); }
public virtual void BeginTransaction() { IsTransactional = true; if (_currentTransaction == null) { _currentTransaction = new UnitOfWorkTransaction(); } foreach (var database in GetAllActiveDatabases()) { if (database is ISupportTransaction databaseSupportTransaction) { var inTransaction = databaseSupportTransaction.IsInTransaction(); if (!inTransaction) { databaseSupportTransaction.BeginTransaction(); _currentTransaction.ChildrenTransactions.Add(databaseSupportTransaction.CurrentTransaction); } } } }
public virtual async Task BeginTransactionAsync(CancellationToken cancellationToken = default) { IsTransactional = true; if (_currentTransaction == null) { _currentTransaction = new UnitOfWorkTransaction(); } foreach (var database in GetAllActiveDatabases()) { if (database is ISupportTransaction databaseSupportTransaction) { var inTransaction = await databaseSupportTransaction.IsInTransactionAsync(cancellationToken); if (!inTransaction) { await databaseSupportTransaction.BeginTransactionAsync(cancellationToken); _currentTransaction.ChildrenTransactions.Add(databaseSupportTransaction.CurrentTransaction); } } } }