private async Task <object> HandleNext(ICommandBase command, CommandBusMiddlewareDelegate next, IUnitOfWork unitOfWork) { ICommandContext newContext = new CommandContext(command, unitOfWork); commandContextStack.Push(newContext); newContext.UnitOfWork?.Begin(); try { var result = await next(command); if (newContext.UnitOfWork != null) { await newContext.UnitOfWork.CommitAsync(); } return(result); } finally { Debug.Assert(commandContextStack.PeekOrDefault == newContext); commandContextStack.Pop(); } }
public Task PreFilterAsync(ICommandBase command) { ICommandContext newContext = new CommandContext(command, unitOfWorkFactory.CreateUnitOfWork()); commandContextStack.Push(newContext); newContext.UnitOfWork.Begin(); return(Task.FromResult(0)); }