public HttpServiceGatewayMiddleware(
            RequestDelegate next,
            ILoggerFactory loggerFactory,
            IHttpCommunicationClientFactory httpCommunicationClientFactory,
            IOptions<HttpServiceGatewayOptions> gatewayOptions)
        {
            if (next == null)
                throw new ArgumentNullException(nameof(next));

            if (loggerFactory == null)
                throw new ArgumentNullException(nameof(loggerFactory));

            if (httpCommunicationClientFactory == null)
                throw new ArgumentNullException(nameof(httpCommunicationClientFactory));

            if (gatewayOptions?.Value == null)
                throw new ArgumentNullException(nameof(gatewayOptions));

            if (gatewayOptions.Value.ServiceName == null)
                throw new ArgumentNullException($"{nameof(gatewayOptions)}.{nameof(gatewayOptions.Value.ServiceName)}");

            // "next" is not stored because this is a terminal middleware
            _logger = loggerFactory.CreateLogger(HttpServiceGatewayDefaults.LoggerName);
            _httpCommunicationClientFactory = httpCommunicationClientFactory;
            _gatewayOptions = gatewayOptions.Value;
        }
        /// <summary>
        /// Adds the <see cref="HttpServiceGatewayMiddleware"/> middleware to the request pipeline.
        /// This middleware is terminal.
        /// </summary>
        /// <param name="options">Options for the <see cref="HttpServiceGatewayMiddleware" />.</param>
        public static IApplicationBuilder RunHttpServiceGateway(this IApplicationBuilder app, HttpServiceGatewayOptions options)
        {
            if (app == null)
                throw new ArgumentNullException(nameof(app));

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

            return app.UseMiddleware<HttpServiceGatewayMiddleware>(Options.Create(options));
        }
        /// <summary>
        /// Adds the <see cref="HttpServiceGatewayMiddleware"/> middleware to the request pipeline.
        /// This middleware is terminal.
        /// </summary>
        /// <param name="app">The application builder instance.</param>
        /// <param name="serviceName">Name of the service within Service Fabric.</param>
        public static IApplicationBuilder RunHttpServiceGateway(this IApplicationBuilder app, string serviceName)
        {
            if (app == null)
                throw new ArgumentNullException(nameof(app));

            if (string.IsNullOrWhiteSpace(serviceName))
                throw new ArgumentNullException(nameof(app));

            HttpServiceGatewayOptions options = new HttpServiceGatewayOptions { ServiceName = new Uri(serviceName) };

            return app.RunHttpServiceGateway(options);
        }
        /// <summary>
        /// Adds the <see cref="HttpServiceGatewayMiddleware"/> middleware to the request pipeline.
        /// This middleware is terminal.
        /// </summary>
        /// <param name="app">The application builder instance.</param>
        /// <param name="pathMatch">The request path to match in the gateway.</param>
        /// <param name="options">Options for the <see cref="HttpServiceGatewayMiddleware" />.</param>
        public static IApplicationBuilder RunHttpServiceGateway(this IApplicationBuilder app, PathString pathMatch, HttpServiceGatewayOptions options)
        {
            if (app == null)
                throw new ArgumentNullException(nameof(app));

            app.Map(pathMatch, x =>
            {
                x.RunHttpServiceGateway(options);
            });

            return app;
        }
        /// <summary>
        /// Adds the <see cref="HttpServiceGatewayMiddleware"/> middleware to the request pipeline.
        /// This middleware is terminal.
        /// </summary>
        /// <param name="app">The application builder instance.</param>
        /// <param name="serviceName">Name of the service within Service Fabric.</param>
        public static IApplicationBuilder RunHttpServiceGateway(this IApplicationBuilder app, string serviceName)
        {
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }

            if (string.IsNullOrWhiteSpace(serviceName))
            {
                throw new ArgumentNullException(nameof(app));
            }

            HttpServiceGatewayOptions options = new HttpServiceGatewayOptions {
                ServiceName = new Uri(serviceName)
            };

            return(app.RunHttpServiceGateway(options));
        }
示例#6
0
        public HttpServiceGatewayMiddleware(
            RequestDelegate next,
            ILoggerFactory loggerFactory,
            IHttpCommunicationClientFactory httpCommunicationClientFactory,
            IOptions <HttpServiceGatewayOptions> gatewayOptions)
        {
            if (next == null)
            {
                throw new ArgumentNullException(nameof(next));
            }

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

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

            if (gatewayOptions?.Value == null)
            {
                throw new ArgumentNullException(nameof(gatewayOptions));
            }

            if (gatewayOptions.Value.ServiceName == null)
            {
                throw new ArgumentNullException($"{nameof(gatewayOptions)}.{nameof(gatewayOptions.Value.ServiceName)}");
            }

            // "next" is not stored because this is a terminal middleware
            _logger = loggerFactory.CreateLogger(HttpServiceGatewayDefaults.LoggerName);
            _httpCommunicationClientFactory = httpCommunicationClientFactory;
            _gatewayOptions = gatewayOptions.Value;
        }
        /// <summary>
        /// Adds the <see cref="HttpServiceGatewayMiddleware"/> middleware to the request pipeline.
        /// This middleware is terminal.
        /// </summary>
        /// <param name="app">The application builder instance.</param>
        /// <param name="options">Options for the <see cref="HttpServiceGatewayMiddleware" />.</param>
        public static IApplicationBuilder RunHttpServiceGateway(this IApplicationBuilder app, HttpServiceGatewayOptions options)
        {
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }

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

            return(app.UseMiddleware <HttpServiceGatewayMiddleware>(Options.Create(options)));
        }
        /// <summary>
        /// Adds the <see cref="HttpServiceGatewayMiddleware"/> middleware to the request pipeline.
        /// This middleware is terminal.
        /// </summary>
        /// <param name="app">The application builder instance.</param>
        /// <param name="pathMatch">The request path to match in the gateway.</param>
        /// <param name="options">Options for the <see cref="HttpServiceGatewayMiddleware" />.</param>
        public static IApplicationBuilder RunHttpServiceGateway(this IApplicationBuilder app, PathString pathMatch, HttpServiceGatewayOptions options)
        {
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }

            app.Map(pathMatch, x =>
            {
                x.RunHttpServiceGateway(options);
            });

            return(app);
        }