Preserve state in HostBuilder.Properties (#1212)

This commit is contained in:
Julian Dominguez 2017-09-15 02:00:44 -07:00 committed by David Fowler
parent ae9da9290e
commit 1c3fa82908
2 changed files with 17 additions and 1 deletions

View File

@ -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"/>

View File

@ -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
{