public static IApplicationBuilder MapReverseProxyWithQueueDelegation(this IApplicationBuilder app)
        {
            IServerDelegationFeature delegationFeature = app.ServerFeatures.Get <IServerDelegationFeature>();

            if (delegationFeature == null)
            {
                throw new NotSupportedException($"The {nameof(IServerDelegationFeature)} is not supported by the current OS.");
            }

            var delegationRuleProvider = new QueueDelegationRuleProvider(
                delegationFeature,
                app.ApplicationServices.GetRequiredService <IProxyConfigProvider>(),
                app.ApplicationServices.GetRequiredService <ILogger <QueueDelegationRuleProvider> >());

            app.ApplicationServices.GetRequiredService <IHostApplicationLifetime>().ApplicationStopped.Register(() => delegationRuleProvider.Dispose());

            app.UseRouting();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapReverseProxy(proxyPipeline =>
                {
                    proxyPipeline.UseMiddleware <QueueDelegationMiddleware>(delegationRuleProvider);
                });
            });

            return(app);
        }
 public QueueDelegationMiddleware(
     RequestDelegate next,
     ILogger <QueueDelegationMiddleware> logger,
     QueueDelegationRuleProvider delegationRuleProvider)
 {
     this.next   = next;
     this.logger = logger;
     this.delegationRuleProvider = delegationRuleProvider;
 }