public static IWebHostBuilder UseNowin(this IWebHostBuilder builder)
 {
     return builder.ConfigureServices(services =>
     {
         services.AddSingleton<IServer, NowinServer>();
     });
 }
 public static IWebHostBuilder UseNowin(this IWebHostBuilder builder, Action<ServerBuilder> configure)
 {
     builder.ConfigureServices(services =>
     {
         services.Configure(configure);
     });
     return builder.UseNowin();
 }
        /// <summary>
        /// Specify the server to be used by the web host.
        /// </summary>
        /// <param name="hostBuilder">The <see cref="IWebHostBuilder"/> to configure.</param>
        /// <param name="server">The <see cref="IServer"/> to be used.</param>
        /// <returns>The <see cref="IWebHostBuilder"/>.</returns>
        public static IWebHostBuilder UseServer(this IWebHostBuilder hostBuilder, IServer server)
        {
            if (server == null)
            {
                throw new ArgumentNullException(nameof(server));
            }

            return hostBuilder.ConfigureServices(services =>
            {
                // It would be nicer if this was transient but we need to pass in the
                // factory instance directly
                services.AddSingleton(server);
            });
        }
        /// <summary>
        /// Configures the port and base path the server should listen on when running behind AspNetCoreModule.
        /// The app will also be configured to capture startup errors.
        /// </summary>
        /// <param name="app"></param>
        /// <returns></returns>
        public static IWebHostBuilder UseIISIntegration(this IWebHostBuilder app)
        {
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }

            var port = app.GetSetting(ServerPort) ?? Environment.GetEnvironmentVariable($"ASPNETCORE_{ServerPort}");
            var path = app.GetSetting(ServerPath) ?? Environment.GetEnvironmentVariable($"ASPNETCORE_{ServerPath}");
            var pairingToken = app.GetSetting(PairingToken) ?? Environment.GetEnvironmentVariable($"ASPNETCORE_{PairingToken}");

            if (!string.IsNullOrEmpty(port) && !string.IsNullOrEmpty(path) && !string.IsNullOrEmpty(pairingToken))
            {
                var address = "http://localhost:" + port + path;
                app.UseSetting(WebHostDefaults.ServerUrlsKey, address);
                app.CaptureStartupErrors(true);

                app.ConfigureServices(services =>
                {
                    services.AddSingleton<IStartupFilter>(new IISSetupFilter(pairingToken));
                    services.Configure<ForwardedHeadersOptions>(options =>
                    {
                        options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;

                        // https://github.com/aspnet/IISIntegration/issues/140
                        // Azure Web Sites needs to be treated specially as we get an imbalanced set of X-Forwarded-* headers.
                        // We use the existence of the %WEBSITE_INSTANCE_ID% environment variable to determine if we're running
                        // in this environment, and if so we disable the symmetry check.
                        var isAzure = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("WEBSITE_INSTANCE_ID"));
                        options.RequireHeaderSymmetry = !isAzure;
                    });
                });
            }

            return app;
        }
        public static IWebHostBuilder UseServiceFabric(this IWebHostBuilder webHostBuilder, ServiceFabricOptions options)
        {
            if (webHostBuilder == null)
            {
                throw new ArgumentNullException(nameof(webHostBuilder));
            }

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

            //
            // Configure server URL.
            //
            var endpoint = FabricRuntime.GetActivationContext().GetEndpoint(options.EndpointName);

            string serverUrl = $"{endpoint.Protocol}://{FabricRuntime.GetNodeContext().IPAddressOrFQDN}:{endpoint.Port}";

            webHostBuilder.UseUrls(serverUrl);

            //
            // Configure services and middlewares.
            //
            webHostBuilder.ConfigureServices(services =>
            {
                if (options.ServiceDescriptions != null && options.ServiceDescriptions.Any())
                {
                    services.AddTransient<IStartupFilter>(serviceProvider => new ServiceFabricStartupFilter(options));

                    services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();

                    foreach (var serviceDescription in options.ServiceDescriptions)
                    {
                        if (serviceDescription.ServiceType != null && serviceDescription.InterfaceTypes != null)
                        {
                            foreach (var interfaceType in serviceDescription.InterfaceTypes)
                            {
                                if (interfaceType != null)
                                {
                                    services.AddScoped(interfaceType, serviceProvider =>
                                    {
                                        var httpContextAccessor = serviceProvider.GetRequiredService<IHttpContextAccessor>();

                                        var feature = httpContextAccessor.HttpContext.Features.Get<ServiceFabricFeature>();

                                        var instanceOrReplica = feature?.InstanceOrReplica;

                                        return instanceOrReplica?.GetType() == serviceDescription.ServiceType ? instanceOrReplica : null;
                                    });
                                }
                            }
                        }
                    }
                }

                if (options.ConfigureServices != null)
                {
                    options.ConfigureServices(services);
                }
            });

            return webHostBuilder;
        }
 public static IWebHostBuilder UseStructureMap(this IWebHostBuilder builder, Registry registry)
 {
     return builder.ConfigureServices(services => services.AddStructureMap(registry));
 }