Skip to content

Instantly share code, notes, and snippets.

@njmube
Forked from jbogard/MediatR.cs
Last active August 29, 2015 14:23
Show Gist options
  • Save njmube/16e1135d325116120eb0 to your computer and use it in GitHub Desktop.
Save njmube/16e1135d325116120eb0 to your computer and use it in GitHub Desktop.
public TResult Send<TResult>(IRequest<TResult> message)
{
var context = Container.GetInstance<MyContext>();
var mediator = Container.GetInstance<IMediator>();
DbContextTransaction txn = null;
TResult result;
try
{
txn = context.Database.BeginTransaction();
result = mediator.Send(message);
txn.Commit();
}
catch (Exception)
{
txn?.Rollback();
throw;
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment