diff --git a/src/Microsoft.Extensions.Hosting/HostBuilder.cs b/src/Microsoft.Extensions.Hosting/HostBuilder.cs index c8eac6aa52..b12914a1a0 100644 --- a/src/Microsoft.Extensions.Hosting/HostBuilder.cs +++ b/src/Microsoft.Extensions.Hosting/HostBuilder.cs @@ -31,7 +31,7 @@ namespace Microsoft.Extensions.Hosting /// /// A central location for sharing state between components during the host building process. /// - public IDictionary Properties => new Dictionary(); + public IDictionary Properties { get; } = new Dictionary(); /// /// Set up the configuration for the builder itself. This will be used to initialize the diff --git a/test/Microsoft.Extensions.Hosting.Tests/HostBuilderTests.cs b/test/Microsoft.Extensions.Hosting.Tests/HostBuilderTests.cs index 0f567837be..450c91ce32 100644 --- a/test/Microsoft.Extensions.Hosting.Tests/HostBuilderTests.cs +++ b/test/Microsoft.Extensions.Hosting.Tests/HostBuilderTests.cs @@ -444,6 +444,22 @@ namespace Microsoft.Extensions.Hosting Assert.Equal(Path.GetFullPath("."), env.ContentRootPath); Assert.IsAssignableFrom(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 {