Beispiel #1
0
        /// <summary>
        /// Adds the <see cref="GatewayMiddleware"/> to the pipeline.
        /// </summary>
        /// <param name="app">
        /// The app.
        /// </param>
        /// <param name="options">
        /// The options.
        /// </param>
        /// <returns>
        /// The <see cref="IApplicationBuilder"/>.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// Either the application builder or the gateway options is null.
        /// </exception>
        public static IApplicationBuilder RunGateway(this IApplicationBuilder app, GatewayOptions options)
        {
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }

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

            return(app.UseMiddleware <GatewayMiddleware>(Options.Create(options)));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="GatewayMiddleware"/> class.
        /// </summary>
        /// <param name="next">
        /// The next.
        /// </param>
        /// <param name="dispatcherProvider">
        /// The dispatcher provider.
        /// </param>
        /// <param name="options">
        /// The options.
        /// </param>
        /// <exception cref="ArgumentNullException">Either the dispatcher provider or the options is null.</exception>
        public GatewayMiddleware(
            RequestDelegate next,
            HttpRequestDispatcherProvider dispatcherProvider,
            IOptions <GatewayOptions> options)
        {
            if (dispatcherProvider == null)
            {
                throw new ArgumentNullException(nameof(dispatcherProvider));
            }

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

            this.dispatcherProvider = dispatcherProvider;
            this.options            = options.Value;
        }