コード例 #1
0
        public async Task <TResponse> Handle(
            TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate <TResponse> next)
        {
            if (request is ICommand <TResponse> == false ||
                _data.HasActiveTransaction)
            {
                return(await next());
            }

            try
            {
                await _data.BeginTransactionAsync();

                var result = await next();

                await _data.CommitAsync();

                return(result);
            }
            catch
            {
                await _data.RollbackTransactionAsync();

                throw;
            }
        }
コード例 #2
0
        public async Task <TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate <TResponse> next)
        {
            if (!request.GetType().IsSubclassOf(typeof(Command <TResponse>)) || _data.HasActiveTransaction)
            {
                return(await next());
            }

            try
            {
                await _data.BeginTransactionAsync();

                TResponse result = await next();

                await _data.CommitAsync();

                return(result);
            }
            catch
            {
                await _data.RollbackTransactionAsync();

                throw;
            }
        }