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); }
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(); }
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(); }
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; } }
public async Task BeginAsync() { await _unitOfWorkManager.BeginAsync(); counter++; }