示例#1
0
        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);
        }
示例#2
0
        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;
     }
 }
示例#5
0
        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);
        }
示例#7
0
        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));
        }
示例#8
0
        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));
 }
示例#10
0
 public override Task <TResponse> Handle(TMessage query)
 {
     _rootProcessRegistrator.RegisterRoot(query);
     return(_decoratee.Handle(query));
 }