Ejemplo n.º 1
0
        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();
            }
        }
Ejemplo n.º 2
0
        public Task PreFilterAsync(ICommandBase command)
        {
            ICommandContext newContext = new CommandContext(command, unitOfWorkFactory.CreateUnitOfWork());

            commandContextStack.Push(newContext);

            newContext.UnitOfWork.Begin();

            return(Task.FromResult(0));
        }