public override async Task <TResult> Handle(TQuery query) { var circuitBreakers = _attributeLookup.GetDeclaratedCircuitBreakers(_decorated.GetType()) .Select(typ => _circuitBreakerRegistry.GetCircuitBreaker(typ)) .ToList(); var protectedCommandsAndQueries = _circuitBreakerRegistry.GetProtectingCircuitBreakers(query.GetType()); if (protectedCommandsAndQueries != null) { circuitBreakers = circuitBreakers.Union(protectedCommandsAndQueries).ToList(); } if (circuitBreakers.IsNullOrEmpty()) { // no circuit breaker for this query, just pass through return(await _decorated.Handle(query).ConfigureAwait(false)); } Func <Task <TResult> > action = () => _decorated.Handle(query); foreach (var circuitBreaker in circuitBreakers) { var innerAction = action; var breaker = circuitBreaker; action = () => breaker.Execute(innerAction); } var result = await action().ConfigureAwait(false); return(result); }
protected override async Task HandleRootCommand(TCommand command) { await _decorated.Handle(command); await _dbContext.SaveChangesAsync(); // don't dispose UoW here, the container disposes it at the end of the web request }
protected override async Task <TResult> HandleRootQuery(TCommand command) { var result = await _decorated.Handle(command); await _dbContext.SaveChangesAsync(); return(result); // don't dispose UoW here, the container disposes it at the end of the web request }
protected override Task HandleRootCommand(TCommand command) { try { return(_decorated.Handle(command)); } catch (Exception ex) { //_eventBus.Publish(new CommandExceptionEvent { Exception = ex, Command = command }); throw; } }
public override async Task <TResult> Handle(TQuery query) { if (_rootProcessRegistrator.IsRootProcess(query)) { var rights = query.GetType().GetCustomAttributes <Kiss4RightAttribute>(); if (!await _authorizationChecker.UserHasRights(rights)) { throw new UnauthorizedAccessException(string.Format(AuthorizationResources.Unauthorized, query.GetType().Name)); } } return(await _decorated.Handle(query)); }
public override async Task Handle(TCommand command) { if (_rootProcessRegistrator.IsRootProcess(command)) { var rights = command.GetType().GetCustomAttributes <Kiss4RightAttribute>(); if (!await _authorizationChecker.UserHasRights(rights)) { throw new UnauthorizedAccessException(string.Format(AuthorizationResources.Unauthorized, command.GetType().Name)); } } await _decorated.Handle(command); }
public override Task <TResult> Handle(TMessage query) { if (_rootProcessRegistrator.RegisterRoot(query)) { return(HandleRootQuery(query)); } if (query is IChildMessage childmessage && childmessage.ParentRequestId == null) { childmessage.ParentRequestId = _rootProcessRegistrator.RootProcessId; } // be transparent if it's not the root query return(_decorated.Handle(query)); }
public override Task Handle(TMessage command) { if (_rootProcessRegistrator.RegisterRoot(command)) { return(HandleRootCommand(command)); } if (command is IChildMessage childmessage && childmessage.ParentRequestId == null) { childmessage.ParentRequestId = _rootProcessRegistrator.RootProcessId; } // be transparent if it's not the root command return(_decorated.Handle(command)); }
public override Task <TResult> Handle(TQuery query) { _dbModelVerifier.VerifyModelAgainstDatabase(); return(_decorated.Handle(query)); }
public override Task <TResponse> Handle(TMessage query) { _rootProcessRegistrator.RegisterRoot(query); return(_decoratee.Handle(query)); }