public async Task Handle_ReturnsMeetup() { var result = await _handler.Handle(new GetMeetupRequest(1)); result.Should().NotBeNull(); result.Meetup.Should().NotBeNull(); }
public Task <TResponse> Handle(TRequest message) { using (LogContext.PushProperty(LogConstants.MediatRRequestType, typeof(TRequest).FullName)) { return(_inner.Handle(message)); } }
public async Task <TResponse> Handle(TRequest message) { var log = LogProvider.For <ExceptionLoggerAsync <TRequest, TResponse> >(); log.Debug("Begin"); try { return(await _inner.Handle(message)); } catch (RecoverableException e) { log.ErrorException(e.StackTrace, e); e.TrackingId = message.TrackingId.ToString(); throw; } catch (Exception e) { log.ErrorException(e.StackTrace, e); throw new ServiceException(e.Message, message.TrackingId.ToString(), e); } finally { log.Debug("End"); } }
public async Task <AccountTransactions> Handle(AccountTransactionsRequest message) { var accountTransactions = await _decoratedHandler.Handle(message); accountTransactions.Transactions = accountTransactions.Transactions.OrderBy(x => x.Type); return(accountTransactions); }
Task <TResponse> IAsyncRequestHandler <TRequest, TResponse> .Handle(TRequest message) { logger.LogRequestInfo <TRequest, TResponse>(message); var response = inner.Handle(message); logger.LogResponseInfo(response); return(response); }
public async Task <TResponse> Handle(TRequest request) { var baseRequest = (BaseRequest)request; log4net.LogicalThreadContext.Properties["TrackingId"] = baseRequest.TrackingId.ToString(); return(await _inner.Handle(request)); }
public async Task Handle_ReturnsMeetups() { var result = await _handler.Handle(new GetMeetupsRequest()); result.Should().NotBeNull(); result.Meetups.Should().NotBeNull(); result.Meetups.Should().HaveCount(1); }
public Task <TResponse> Handle(TRequest message) { var name = typeof(TRequest).FullName; using (Metrics.Time(name, elapsed => _logger.LogInformation($"{name} executed, time elapsed {elapsed}"))) { return(_inner.Handle(message)); } }
public async Task <TResponse> Handle(TRequest message) { _log.Info(string.Format("Request: {0}", message)); var response = await _innerHander.Handle(message); _log.Info(string.Format("Response: {0}", response)); return(response); }
public async Task <TResponse> Handle(TRequest message) { foreach (var preRequestHandler in _preRequestHandlers) { await preRequestHandler.Handle(message); } return(await _inner.Handle(message)); }
public async Task <TResponse> Handle(TRequest message) { _logger.LogInformation($"Executing command {_inner.GetType().FullName}"); var response = await _inner.Handle(message); _logger.LogInformation($"Command executed successfully {_inner.GetType().FullName}"); return(response); }
public async Task <TResult> Handle(TRequest request) { _logger("Before handling request of type " + typeof(TRequest).Name); var result = await _innerHandler.Handle(request); _logger("After request was handled"); return(result); }
/// <summary> /// Registers an <see cref="IAsyncRequestHandler{TRequest, TResponse}"/> /// </summary> /// <typeparam name="TRequest">Type of request message</typeparam> /// <typeparam name="TResponse">Type of response message</typeparam> /// <param name="handler">Request handler instance</param> public void Register <TRequest, TResponse>(IAsyncRequestHandler <TRequest, TResponse> handler) { ValidateTypes <TRequest, TResponse>(); requestHandlers.Add( typeof(TRequest), request => handler .Handle((TRequest)request) .GetAwaiter() .GetResult()); }
public Task <TResponse> Handle(TRequest message) { var context = new ValidationContext(message); var failures = _validators.Select(v => v.Validate(context)) .SelectMany(result => result.Errors) .Where(f => f != null) .ToList(); return(_inner.Handle(message)); }
async Task <TResponse> IAsyncRequestHandler <TRequest, TResponse> .Handle(TRequest message) { try { return(await _inner.Handle(message)); } catch (Exception exception) { _dbConnectionProvider.PrventCommit(); throw exception; } }
public async Task <TResponse> Handle(TRequest message) { if (!(message is IValidable)) { return(await _inner.Handle(message)); } var context = new ValidationContext(message); var failures = _validators .Select(v => v.Validate(context)) .SelectMany(result => result.Errors) .Where(f => f != null) .ToList(); if (failures.Any()) { throw new ValidationException(failures); } return(await _inner.Handle(message)); }
public async Task <TResult> Handle(TRequest request) { var innerMostHandler = GetInnerMostHandler(); var authAttribute = innerMostHandler.GetType().GetMethod("Handle").GetCustomAttribute(typeof(AuthorizeAttribute)) as AuthorizeAttribute; if (!string.IsNullOrEmpty(authAttribute.Roles)) { new PrincipalPermission(null, authAttribute.Roles).Demand(); } return(await _innerHandler.Handle(request)); }
public async Task <TResponse> Handle(TRequest message) { // This will be our parent scope using (var dbContextScope = _dbContextScopeFactory.Create()) { var result = await _inner.Handle(message); // Only the outermost DbContextScope's save changes is respected. // For Queries this will not result in any Db Transaction, because there was no change to the EF Context await dbContextScope.SaveChangesAsync(); return(result); } }
async Task <TResponse> IAsyncRequestHandler <TRequest, TResponse> .Handle(TRequest request) { foreach (var messageProcessor in _processors) { await messageProcessor.OnBeforeRequestAsync(request); } var result = await _inner.Handle(request); foreach (var messageProcessor in _processors) { messageProcessor.OnRequestHandled(request, result); } return(result); }
public Task <TResponse> Handle(TRequest message) { var failuers = _validators .Select(v => v.Validate(message)) .SelectMany(result => result.Errors) .Where(f => f != null) .ToList(); if (failuers.Any()) { throw new ValidationException(failuers); } return(_inner.Handle(message)); }
public async Task <TResponse> Handle(TRequest message) { foreach (var preRequestHandler in _preRequestHandlers) { await preRequestHandler.Handle(message); } var result = await _inner.Handle(message); foreach (var postRequestHandler in _postRequestHandlers) { await postRequestHandler.Handle(message, result); } return(result); }
public Task <TResponse> Handle(TRequest message) { List <string> errors = new List <string>(); if (_validators != null && _validators.Any()) { errors = _validators.Where(v => v.Fails(message)) .Select(v => v.ErrorMessage); } if (errors.Any()) { throw new ValidationException(errors); } return(_inner.Handle(message)); }
public Task <TResponse> Handle(TRequest request) { var index = -1; Func <TRequest, Task <TResponse> > next = null; next = req => { ++index; return(index < _middleware.Length ? _middleware[index].Apply(request, next) : _inner.Handle(request)); }; Env.Use(new PipelineContext(ProxyUtil.GetUnproxiedType(_inner))); return(next(request)); }
public Task <TResponse> Handle(TRequest request) { var context = new ValidationContext(request); var failures = _validators .Select(v => v.Validate(context)) .SelectMany(result => result.Errors) .Where(f => f != null) .ToList(); if (failures.Any()) { throw new ValidationException(failures); } return(_inner.Handle(request)); }
public async Task <TResponse> Handle(TRequest message) { var failures = _validators .Select(v => v.Validate(message)) .SelectMany(result => result.Errors) .Where(error => error != null) .ToList(); if (failures.Any()) { throw new DepartmentDomainException( $"Command Validation Errors for type {typeof(TRequest).Name}", new ValidationException("Validation exception", failures)); } var response = await _inner.Handle(message); return(response); }
public Task <TResponse> Handle(TRequest message) { var auditableCommand = message as IAmAuditable; if (auditableCommand != null) { auditableCommand.CommandDate = DateTime.Now; if (_loggedOnUser.IsAuthenticated) { auditableCommand.UserId = _loggedOnUser.Id; auditableCommand.UserName = _loggedOnUser.UserName; } } var result = _inner.Handle(message); return(result); }
public async Task <TResponse> Handle(TRequest message) { try { _db.BeginTransaction(); var response = await _inner.Handle(message); await _db.CommitTransactionAsync(); return(response); } catch (Exception) { _db.RollbackTransaction(); throw; } }
public IObservable <TResponse> Handle(TRequest message) { return(Observable.Create <TResponse>(o => { foreach (var preRequestHandler in _preRequestHandlers.Where(w => w != null)) { preRequestHandler.Handle(message); } return _inner.Handle(message) .Select(result => { foreach (var postRequestHandler in _postRequestHandlers.Where(w => w != null)) { postRequestHandler.Handle(message, result); } return result; }) .Subscribe(o); })); }
public async Task <TResponse> Handle(TRequest message) { Logger.Trace("Handle"); foreach (var preRequestHandler in preRequestHandlers) { await preRequestHandler.Handle(message); } var result = await inner.Handle(message); if (result != null) { foreach (var postRequestHandler in postRequestHandlers) { await postRequestHandler.Handle(message, result); } } return(result); }
public async Task <TResponse> Handle(TRequest message) { return(await _innerHandler.Handle(message)); }