Exemple #1
0
        public Response <IDelegatingHandlerHandlerProvider> Get(DownstreamReRoute request)
        {
            var handlersAppliedToAll = _allRoutesProvider.Get();

            var provider = new DelegatingHandlerHandlerProvider();

            foreach (var handler in handlersAppliedToAll)
            {
                provider.Add(handler);
            }

            if (request.HttpHandlerOptions.UseTracing)
            {
                provider.Add(() => (DelegatingHandler)_factory.Get());
            }

            if (request.IsQos)
            {
                var qosProvider = _qosProviderHouse.Get(request);

                if (qosProvider.IsError)
                {
                    return(new ErrorResponse <IDelegatingHandlerHandlerProvider>(qosProvider.Errors));
                }

                provider.Add(() => new PollyCircuitBreakingDelegatingHandler(qosProvider.Data, _loggerFactory));
            }

            return(new OkResponse <IDelegatingHandlerHandlerProvider>(provider));
        }
Exemple #2
0
        public Response <List <Func <DelegatingHandler> > > Get(DownstreamReRoute downstreamReRoute)
        {
            var globalDelegatingHandlers = _serviceProvider
                                           .GetServices <GlobalDelegatingHandler>()
                                           .ToList();

            var reRouteSpecificHandlers = _serviceProvider
                                          .GetServices <DelegatingHandler>()
                                          .ToList();

            var handlers = new List <Func <DelegatingHandler> >();

            foreach (var handler in globalDelegatingHandlers)
            {
                if (GlobalIsInHandlersConfig(downstreamReRoute, handler))
                {
                    reRouteSpecificHandlers.Add(handler.DelegatingHandler);
                }
                else
                {
                    handlers.Add(() => handler.DelegatingHandler);
                }
            }

            if (downstreamReRoute.DelegatingHandlers.Any())
            {
                var sorted = SortByConfigOrder(downstreamReRoute, reRouteSpecificHandlers);

                foreach (var handler in sorted)
                {
                    handlers.Add(() => handler);
                }
            }

            if (downstreamReRoute.HttpHandlerOptions.UseTracing)
            {
                handlers.Add(() => (DelegatingHandler)_tracingFactory.Get());
            }

            if (downstreamReRoute.QosOptions.UseQos)
            {
                var handler = _qoSFactory.Get(downstreamReRoute);

                if (handler != null && !handler.IsError)
                {
                    handlers.Add(() => handler.Data);
                }
                else
                {
                    _logger.LogWarning($"ReRoute {downstreamReRoute.UpstreamPathTemplate} specifies use QoS but no QosHandler found in DI container. Will use not use a QosHandler, please check your setup!");
                    handlers.Add(() => new NoQosDelegatingHandler());
                }
            }

            return(new OkResponse <List <Func <DelegatingHandler> > >(handlers));
        }
        public Response <List <Func <DelegatingHandler> > > Get(DownstreamReRoute request)
        {
            var globalDelegatingHandlers = _serviceProvider
                                           .GetServices <GlobalDelegatingHandler>()
                                           .ToList();

            var reRouteSpecificHandlers = _serviceProvider
                                          .GetServices <DelegatingHandler>()
                                          .ToList();

            var handlers = new List <Func <DelegatingHandler> >();

            foreach (var handler in globalDelegatingHandlers)
            {
                if (GlobalIsInHandlersConfig(request, handler))
                {
                    reRouteSpecificHandlers.Add(handler.DelegatingHandler);
                }
                else
                {
                    handlers.Add(() => handler.DelegatingHandler);
                }
            }

            if (request.DelegatingHandlers.Any())
            {
                var sorted = SortByConfigOrder(request, reRouteSpecificHandlers);

                foreach (var handler in sorted)
                {
                    handlers.Add(() => handler);
                }
            }

            if (request.HttpHandlerOptions.UseTracing)
            {
                handlers.Add(() => (DelegatingHandler)_tracingFactory.Get());
            }

            if (request.QosOptions.UseQos)
            {
                var handler = _qoSFactory.Get(request);

                if (handler != null && !handler.IsError)
                {
                    handlers.Add(() => handler.Data);
                }
                else
                {
                    return(new ErrorResponse <List <Func <DelegatingHandler> > >(handler?.Errors));
                }
            }

            return(new OkResponse <List <Func <DelegatingHandler> > >(handlers));
        }
        public Response <List <Func <DelegatingHandler> > > Get(DownstreamReRoute request)
        {
            var globalDelegatingHandlers = _serviceProvider
                                           .GetServices <GlobalDelegatingHandler>()
                                           .ToList();

            var reRouteSpecificHandlers = _serviceProvider
                                          .GetServices <DelegatingHandler>()
                                          .ToList();

            var handlers = new List <Func <DelegatingHandler> >();

            foreach (var handler in globalDelegatingHandlers)
            {
                if (GlobalIsInHandlersConfig(request, handler))
                {
                    reRouteSpecificHandlers.Add(handler.DelegatingHandler);
                }
                else
                {
                    handlers.Add(() => handler.DelegatingHandler);
                }
            }

            if (request.DelegatingHandlers.Any())
            {
                var sorted = SortByConfigOrder(request, reRouteSpecificHandlers);

                foreach (var handler in sorted)
                {
                    handlers.Add(() => handler);
                }
            }

            if (request.HttpHandlerOptions.UseTracing)
            {
                handlers.Add(() => (DelegatingHandler)_factory.Get());
            }

            if (request.IsQos)
            {
                var qosProvider = _qosProviderHouse.Get(request);

                if (qosProvider.IsError)
                {
                    return(new ErrorResponse <List <Func <DelegatingHandler> > >(qosProvider.Errors));
                }

                handlers.Add(() => new PollyCircuitBreakingDelegatingHandler(qosProvider.Data, _loggerFactory));
            }

            return(new OkResponse <List <Func <DelegatingHandler> > >(handlers));
        }