public async Task <TResponse> Handle(TRequest message) { try { _db.BeginTransaction(); var response = await _inner.Handle(message); await _db.CommitTransactionAsync(); return(response); } catch (Exception) { _db.RollbackTransaction(); throw; } }
public TResponse Handle(TRequest message) { try { _db.BeginTransaction(); var response = _inner.Handle(message); _db.CommitTransactionAsync().Wait(); return(response); } catch (Exception) { _db.RollbackTransaction(); throw; } }
public void DoClean(Action <DbContext> action) { var connString = LocalDbFactory.Instance.CreateConnectionStringBuilder(); connString.InitialCatalog = "ContosoUniversity"; var dbContext = new SchoolContext(connString.ToString()); try { dbContext.BeginTransaction(); action(dbContext); dbContext.CloseTransaction(); } catch (Exception e) { dbContext.CloseTransaction(e); throw; } }