public async Task InvokeAsync(HttpContext context, IUnitOfWorkManager unitOfWorkManager)
        {
            await unitOfWorkManager.BeginAsync().ConfigureAwait(false);

            try
            {
                await _next(context).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                await unitOfWorkManager.EndAsync(ex).ConfigureAwait(false);

                throw;
            }

            await unitOfWorkManager.EndAsync().ConfigureAwait(false);
        }
Exemplo n.º 2
0
        public async Task Handle(T command, CancellationToken cancellationToken = default)
        {
            await _unitOfWorkManager.BeginAsync();

            try
            {
                await _handler.Handle(command, cancellationToken);
            }
            catch (Exception ex)
            {
                await _unitOfWorkManager.EndAsync(ex);

                throw;
            }

            await _unitOfWorkManager.EndAsync();
        }
Exemplo n.º 3
0
        public async Task EndAsync(Exception ex = null)
        {
            if (errorHandled)
            {
                return;
            }

            if (ex != null)
            {
                await _unitOfWorkManager.EndAsync(ex);

                errorHandled = true;
            }
            else
            {
                counter--;
                if (counter == 0)
                {
                    await _unitOfWorkManager.EndAsync();
                }
            }
        }
Exemplo n.º 4
0
        public async Task SendMany <TCommands>(TCommands commands, CancellationToken cancellationToken = default) where TCommands : IEnumerable <ICommand>
        {
            await _unitOfWorkManager.BeginAsync();

            try
            {
                foreach (var command in commands)
                {
                    if (command is ILockIdentifier)
                    {
                        throw new NotSupportedException("Not currently possible to dispatch multiple commands if any implement the ILockIdentifier interface");
                    }
                    await Send(command as dynamic, cancellationToken);
                }
            }
            catch (Exception ex)
            {
                await _unitOfWorkManager.EndAsync(ex);

                throw;
            }

            await _unitOfWorkManager.EndAsync();
        }
Exemplo n.º 5
0
        public async Task <TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate <TResponse> next)
        {
            if (!(request is IUnitOfWorkCommand))
            {
                return(await next());
            }

            await _unitOfWorkManager.BeginAsync();

            try
            {
                var response = await next();

                await _unitOfWorkManager.EndAsync();

                return(response);
            }
            catch (Exception e)
            {
                await _unitOfWorkManager.EndAsync(e);

                throw;
            }
        }