Preserve state in HostBuilder.Properties (#1212)
This commit is contained in:
parent
ae9da9290e
commit
1c3fa82908
|
|
@ -31,7 +31,7 @@ namespace Microsoft.Extensions.Hosting
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A central location for sharing state between components during the host building process.
|
/// A central location for sharing state between components during the host building process.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IDictionary<object, object> Properties => new Dictionary<object, object>();
|
public IDictionary<object, object> Properties { get; } = new Dictionary<object, object>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Set up the configuration for the builder itself. This will be used to initialize the <see cref="IHostingEnvironment"/>
|
/// Set up the configuration for the builder itself. This will be used to initialize the <see cref="IHostingEnvironment"/>
|
||||||
|
|
|
||||||
|
|
@ -444,6 +444,22 @@ namespace Microsoft.Extensions.Hosting
|
||||||
Assert.Equal(Path.GetFullPath("."), env.ContentRootPath);
|
Assert.Equal(Path.GetFullPath("."), env.ContentRootPath);
|
||||||
Assert.IsAssignableFrom<PhysicalFileProvider>(env.ContentRootFileProvider);
|
Assert.IsAssignableFrom<PhysicalFileProvider>(env.ContentRootFileProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void BuilderPropertiesAreAvailableInBuilderAndContext()
|
||||||
|
{
|
||||||
|
var hostBuilder = new HostBuilder()
|
||||||
|
.ConfigureServices((hostContext, services) =>
|
||||||
|
{
|
||||||
|
Assert.Equal("value", hostContext.Properties["key"]);
|
||||||
|
});
|
||||||
|
|
||||||
|
hostBuilder.Properties.Add("key", "value");
|
||||||
|
|
||||||
|
Assert.Equal("value", hostBuilder.Properties["key"]);
|
||||||
|
|
||||||
|
using (hostBuilder.Build()) { }
|
||||||
|
}
|
||||||
|
|
||||||
private class ServiceC
|
private class ServiceC
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue