Add KestrelServerOptionsSetup to IServiceCollection in UseKestrel() (#755)
- Previously, KestrelServerOptionsSetup was only added to IServiceCollection in UseKestrel(options) - Required to ensure that options.ApplicationServices is available after calling UseKestrel()
This commit is contained in:
parent
c48353f4ef
commit
bbf2c83a7d
|
|
@ -23,7 +23,11 @@ namespace Microsoft.AspNetCore.Hosting
|
|||
/// </returns>
|
||||
public static IWebHostBuilder UseKestrel(this IWebHostBuilder hostBuilder)
|
||||
{
|
||||
return hostBuilder.ConfigureServices(services => services.AddSingleton<IServer, KestrelServer>());
|
||||
return hostBuilder.ConfigureServices(services =>
|
||||
{
|
||||
services.AddTransient<IConfigureOptions<KestrelServerOptions>, KestrelServerOptionsSetup>();
|
||||
services.AddSingleton<IServer, KestrelServer>();
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -42,7 +46,6 @@ namespace Microsoft.AspNetCore.Hosting
|
|||
{
|
||||
hostBuilder.ConfigureServices(services =>
|
||||
{
|
||||
services.AddTransient<IConfigureOptions<KestrelServerOptions>, KestrelServerOptionsSetup>();
|
||||
services.Configure(options);
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Server.Kestrel;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||
{
|
||||
public class WebHostBuilderKestrelExtensionsTests
|
||||
{
|
||||
[Fact]
|
||||
public void ApplicationServicesNotNullAfterUseKestrelWithoutOptions()
|
||||
{
|
||||
// Arrange
|
||||
var hostBuilder = new WebHostBuilder()
|
||||
.UseKestrel()
|
||||
.Configure(app => { });
|
||||
|
||||
hostBuilder.ConfigureServices(services =>
|
||||
{
|
||||
services.Configure<KestrelServerOptions>(options =>
|
||||
{
|
||||
// Assert
|
||||
Assert.NotNull(options.ApplicationServices);
|
||||
});
|
||||
});
|
||||
|
||||
// Act
|
||||
var host = hostBuilder.Build();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue