From 6b0684cc4df5e6beb0a8cd98acaa00f3fda58d53 Mon Sep 17 00:00:00 2001 From: Chris R Date: Mon, 18 Apr 2016 13:04:05 -0700 Subject: [PATCH] Fix WebListenerOptionsSetup service registration --- samples/SelfHostServer/Startup.cs | 11 +++++++++++ .../WebHostBuilderWebListenerExtensions.cs | 6 ++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/samples/SelfHostServer/Startup.cs b/samples/SelfHostServer/Startup.cs index 0e276faca8..06e833b074 100644 --- a/samples/SelfHostServer/Startup.cs +++ b/samples/SelfHostServer/Startup.cs @@ -6,6 +6,8 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Server.WebListener; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Net.Http.Server; @@ -13,6 +15,15 @@ namespace SelfHostServer { public class Startup { + public void ConfigureServices(IServiceCollection services) + { + // Server options can be configured here instead of in Main. + services.Configure(options => + { + options.Listener.AuthenticationManager.AuthenticationSchemes = AuthenticationSchemes.AllowAnonymous; + }); + } + public void Configure(IApplicationBuilder app, ILoggerFactory loggerfactory) { loggerfactory.AddConsole(LogLevel.Debug); diff --git a/src/Microsoft.AspNetCore.Server.WebListener/WebHostBuilderWebListenerExtensions.cs b/src/Microsoft.AspNetCore.Server.WebListener/WebHostBuilderWebListenerExtensions.cs index f2cfe9deb2..0558a95703 100644 --- a/src/Microsoft.AspNetCore.Server.WebListener/WebHostBuilderWebListenerExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.WebListener/WebHostBuilderWebListenerExtensions.cs @@ -40,7 +40,10 @@ namespace Microsoft.AspNetCore.Hosting /// public static IWebHostBuilder UseWebListener(this IWebHostBuilder hostBuilder) { - return hostBuilder.ConfigureServices(services => services.AddSingleton()); + return hostBuilder.ConfigureServices(services => { + services.AddTransient, WebListenerOptionsSetup>(); + services.AddSingleton(); + }); } /// @@ -59,7 +62,6 @@ namespace Microsoft.AspNetCore.Hosting { hostBuilder.ConfigureServices(services => { - services.AddTransient, WebListenerOptionsSetup>(); services.Configure(options); });