parent
17e5be6fbc
commit
91514c9af7
|
|
@ -327,7 +327,10 @@ namespace Microsoft.AspNetCore.Hosting.Internal
|
||||||
return webHostBuilderContext;
|
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)
|
public string GetSetting(string key)
|
||||||
|
|
|
||||||
|
|
@ -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]
|
[Theory]
|
||||||
[MemberData(nameof(DefaultWebHostBuildersWithConfig))]
|
[MemberData(nameof(DefaultWebHostBuildersWithConfig))]
|
||||||
public void Build_DoesRunHostingStartupFromPrimaryAssemblyEvenIfNotSpecified(IWebHostBuilder builder)
|
public void Build_DoesRunHostingStartupFromPrimaryAssemblyEvenIfNotSpecified(IWebHostBuilder builder)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue