示例#1
0
        public static IOcelotPipelineBuilder MapWhen(this IOcelotPipelineBuilder app, Predicate predicate, Action <IOcelotPipelineBuilder> configuration)
        {
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }

            if (predicate == null)
            {
                throw new ArgumentNullException(nameof(predicate));
            }

            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            var branchBuilder = app.New();

            configuration(branchBuilder);
            var branch = branchBuilder.Build();

            var options = new MapWhenOptions
            {
                Predicate = predicate,
                Branch    = branch,
            };

            return(app.Use(next => new MapWhenMiddleware(next, options).Invoke));
        }
示例#2
0
        public MapWhenMiddleware(OcelotRequestDelegate next, MapWhenOptions options)
        {
            if (next == null)
            {
                throw new ArgumentNullException(nameof(next));
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _next    = next;
            _options = options;
        }
示例#3
0
        public static IOcelotPipelineBuilder MapWhen(this IOcelotPipelineBuilder app, Func <IOcelotPipelineBuilder, Predicate> pipelineBuilderFunc)
        {
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }
            if (pipelineBuilderFunc == null)
            {
                throw new ArgumentNullException(nameof(pipelineBuilderFunc));
            }
            var branchBuilder = app.New();
            var predicate     = pipelineBuilderFunc.Invoke(app);
            var branch        = branchBuilder.Build();

            var options = new MapWhenOptions
            {
                Predicate = predicate,
                Branch    = branch
            };

            return(app.Use(next => new MapWhenMiddleware(next, options).Invoke));
        }