Update generic host wrapper config #6765 (#6770)

This commit is contained in:
Chris Ross 2019-01-16 16:44:17 -08:00 committed by GitHub
parent 17e5be6fbc
commit 91514c9af7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 1 deletions

View File

@ -327,7 +327,10 @@ namespace Microsoft.AspNetCore.Hosting.Internal
return webHostBuilderContext;
}
return (WebHostBuilderContext)contextVal;
// Refresh config, it's periodically updated/replaced
var webHostContext = (WebHostBuilderContext)contextVal;
webHostContext.Configuration = context.Configuration;
return webHostContext;
}
public string GetSetting(string key)

View File

@ -945,6 +945,54 @@ namespace Microsoft.AspNetCore.Hosting
}
}
[Theory]
[MemberData(nameof(DefaultWebHostBuildersWithConfig))]
public void Build_AppConfigAvailableEverywhere(IWebHostBuilder builder)
{
builder = builder
.CaptureStartupErrors(false)
.ConfigureAppConfiguration((context, configurationBuilder) => {
configurationBuilder.AddInMemoryCollection(
new[]
{
new KeyValuePair<string,string>("appconfig", "appvalue")
});
})
.ConfigureLogging((context, logging) =>
{
Assert.Equal("appvalue", context.Configuration["appconfig"]);
})
.ConfigureServices((context, services) =>
{
Assert.Equal("appvalue", context.Configuration["appconfig"]);
})
.UseDefaultServiceProvider((context, services) =>
{
Assert.Equal("appvalue", context.Configuration["appconfig"]);
})
.UseStartup<StartupCheckConfig>()
.UseServer(new TestServer());
using (var host = builder.Build())
{
var configuration = host.Services.GetRequiredService<IConfiguration>();
Assert.Equal("appvalue", configuration["appconfig"]);
}
}
public class StartupCheckConfig
{
public StartupCheckConfig(IConfiguration config)
{
Assert.Equal("value", config["testhostingstartup:config"]);
}
public void Configure(IApplicationBuilder app)
{
}
}
[Theory]
[MemberData(nameof(DefaultWebHostBuildersWithConfig))]
public void Build_DoesRunHostingStartupFromPrimaryAssemblyEvenIfNotSpecified(IWebHostBuilder builder)