Preserve state in HostBuilder.Properties (#1212)
This commit is contained in:
parent
ae9da9290e
commit
1c3fa82908
|
|
@ -31,7 +31,7 @@ namespace Microsoft.Extensions.Hosting
|
|||
/// <summary>
|
||||
/// A central location for sharing state between components during the host building process.
|
||||
/// </summary>
|
||||
public IDictionary<object, object> Properties => new Dictionary<object, object>();
|
||||
public IDictionary<object, object> Properties { get; } = new Dictionary<object, object>();
|
||||
|
||||
/// <summary>
|
||||
/// 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.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
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue