public async Task Commit() { if (ManagedObject == null) { throw new Exception(); } using (var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { _eventSender.SendEvents(ManagedObject.GetEventsToSend()); ManagedObject.ClearEvents(); if (ManagedObject.State != EntityState.Unchanged) { await _repository.Save(ManagedObject); } await _distributedCache.AddOrUpdateEntry(_distributedCacheEntryOptions, CacheKey, ManagedObject); transaction.Complete(); } }