public async Task <TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate <TResponse> next)
        {
            var response = default(TResponse);

            try
            {
                if (_context.HasActiveTransaction || !(request is ICommand || request is ICommand <TResponse>))
                {
                    return(await next());
                }

                using (var transaction = await _context.BeginTransactionAsync())
                {
                    response = await next();

                    await _context.CommitTransactionAsync(transaction);
                }

                return(response);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 2
0
        public async Task ExecuteAsync(Func <Task> action)
        {
            if (_context != null)
            {
                using (var transaction = await _context.BeginTransactionAsync())
                {
                    await action();

                    await _context.CommitTransactionAsync(transaction);
                }
            }
        }