/// <summary>
 /// Initializes a new instance.
 /// </summary>
 /// <param name="next"></param>
 /// <param name="services"></param>
 /// <param name="serviceType"></param>
 /// <param name="binding"></param>
 protected AspNetCoreServiceHostMiddleware(
     RequestDelegate next,
     IServiceProvider services,
     Type serviceType,
     AspNetCoreBindingBase binding) :
     this(next, services, binding)
 {
     this.host = new ServiceHost(serviceType, baseUri);
     host.Description.Behaviors.Add(new AspNetCoreServiceBehavior(router));
     host.Description.Behaviors.Add(new ServiceThrottlingBehavior()
     {
         MaxConcurrentSessions = 10
     });
 }
        /// <summary>
        /// Initializes a new instance.
        /// </summary>
        /// <param name="next"></param>
        /// <param name="services"></param>
        /// <param name="binding"></param>
        AspNetCoreServiceHostMiddleware(
            RequestDelegate next,
            IServiceProvider services,
            AspNetCoreBindingBase binding)
        {
            this.next     = next;
            this.services = services ?? throw new ArgumentNullException(nameof(services));
            this.binding  = binding ?? throw new ArgumentNullException(nameof(binding));
            this.router   = new AspNetCoreRequestRouter();
            this.baseUri  = AspNetCoreUri.GetUri("/" + Guid.NewGuid().ToString("N") + "/");

            // register for cleanup when application is stopped
            services.GetRequiredService <IApplicationLifetime>().ApplicationStopping.Register(() => host.Close());
        }