예제 #1
0
        public override TOut Handle(TIn input)
        {
            var result = Decoratee.Handle(input);

            _logger.LogInformation($"{Decoratee.GetType().Name} : {input.ToString()} => {result.ToString()}");
            return(result);
        }
예제 #2
0
        public override TOut Handle(TIn input)
        {
            var result = Decoratee.Handle(input);

            _context.SaveChanges();
            return(result);
        }
        public EitherAsync <Error, TResponse> Handle(TRequest request)
        {
            var logger = Log.ForContext(RootInstance.GetType());

            logger.Debug("Handling request {@Request}", request);
            var result = Decoratee.Handle(request)
                         .Do(_ => logger.Debug("Request handling complete."));

            return(result);
        }
        public EitherAsync <Error, TResponse> Handle(TRequest request)
        {
            var featureEnabled = GetFeatureInfo(RootInstance)
                                 .MapAsync(async fi => await _featureManager.IsEnabledAsync(fi.Action, fi.Context)).Map(p => p.Match(
                                                                                                                            Right: enabled => enabled
                                ? (Either <Error, Unit>)Unit.Default
                                : Error.FeatureDisabled(),
                                                                                                                            Left: e => e
                                                                                                                            ))
                                 .ToAsync();

            return(featureEnabled.Bind(_ => Decoratee.Handle(request)));
        }
예제 #5
0
        public EitherAsync <Error, TResponse> Handle(TRequest request)
        {
            var permissionEnabled = ExtractPermissionToCheck(RootInstance)
                                    .MapAsync(async perm => await _authZService.CheckAccess(perm))
                                    .Map(p => p.Match(
                                             Right: allowed => allowed
                                                        ? (Either <Error, Unit>)Unit.Default
                                                        : Error.NotAuthorized("No permission"),
                                             Left: e => e
                                             ))
                                    .ToAsync();

            return(permissionEnabled.Bind(_ => Decoratee.Handle(request)));
        }
예제 #6
0
        protected override bool HandleCallback(
            object callback, bool greedy, IHandler composer)
        {
            var composition = callback as Composition;
            var options     = (composition?.Callback ?? callback) as T;
            var handled     = options != null;

            if (handled)
            {
                _options.MergeInto(options);
            }
            return(handled && !greedy ||
                   (Decoratee.Handle(callback, greedy, composer) || handled));
        }
예제 #7
0
        public override TOut Handle(TIn input)
        {
            _timer.Start();
            var result = Decoratee.Handle(input);

            _timer.Stop();

            if (_timer.ElapsedMilliseconds > 500)
            {
                _logger.LogWarning($"Долгий запрос: {typeof(TIn).Name} = {_timer.ElapsedMilliseconds} milliseconds");
            }

            return(result);
        }
예제 #8
0
        public override TOut Handle(TIn input)
        {
            var errors = _validators
                         .Select(x => x.Validate(input))
                         .Where(x => !x.IsValid)
                         .SelectMany(x => x.Errors)
                         .ToList();

            if (errors.Count != 0)
            {
                throw new ValidationException(new Fail(errors));
            }

            return(Decoratee.Handle(input));
        }
예제 #9
0
        public EitherAsync <Error, TResponse> Handle(TRequest request)
        {
            var result = Decoratee.Handle(request);

            return(result.Match <Either <Error, TResponse> >(
                       Right: r =>
            {
                if (RootInstance is ICanProduceEvent eventProducer)
                {
                    if (eventProducer.DomainEvents == null)
                    {
                        return Error.DesignViolation(
                            "DomainEvents property should be initialized when you inherit ICanProduceEvents interface");
                    }

                    PublishAllRegisteredEvents(eventProducer)
                    .Wait();
                }

                return r;
            },
                       e => e)
                   .ToAsync());
        }