public async Task CommitAsync() { try { using (var transaction = await _dbContext.Database.BeginTransactionAsync()) { try { await _dbContext.SaveChangesAsync(); if (!await _messageBus.IsAliveAsync()) { throw new ServiceMessageBusUnavailableException(); } transaction.Commit(); foreach (var e in DomainEvents.GetEvents()) { await _messageBus.PublishAsync(e); } DomainEvents.ClearEvents(); } catch (Exception) { transaction.Rollback(); throw; } } } catch (Exception) { throw; } }