Fix WebListenerOptionsSetup service registration

This commit is contained in:
Chris R 2016-04-18 13:04:05 -07:00
parent ff95748d7e
commit 6b0684cc4d
2 changed files with 15 additions and 2 deletions

View File

@ -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<WebListenerOptions>(options =>
{
options.Listener.AuthenticationManager.AuthenticationSchemes = AuthenticationSchemes.AllowAnonymous;
});
}
public void Configure(IApplicationBuilder app, ILoggerFactory loggerfactory)
{
loggerfactory.AddConsole(LogLevel.Debug);

View File

@ -40,7 +40,10 @@ namespace Microsoft.AspNetCore.Hosting
/// </returns>
public static IWebHostBuilder UseWebListener(this IWebHostBuilder hostBuilder)
{
return hostBuilder.ConfigureServices(services => services.AddSingleton<IServer, MessagePump>());
return hostBuilder.ConfigureServices(services => {
services.AddTransient<IConfigureOptions<WebListenerOptions>, WebListenerOptionsSetup>();
services.AddSingleton<IServer, MessagePump>();
});
}
/// <summary>
@ -59,7 +62,6 @@ namespace Microsoft.AspNetCore.Hosting
{
hostBuilder.ConfigureServices(services =>
{
services.AddTransient<IConfigureOptions<WebListenerOptions>, WebListenerOptionsSetup>();
services.Configure(options);
});