From d89f66f150f7a321895a02f77e4f39b1b2398ce6 Mon Sep 17 00:00:00 2001 From: Derek Gray Date: Tue, 21 Mar 2017 14:31:01 -0500 Subject: [PATCH] Use a CopyOnWriteDictionary in ApplicationBuilder so branches can set their own properties Fix #783 --- .../Internal/ApplicationBuilder.cs | 2 +- .../Microsoft.AspNetCore.Http.csproj | 1 + .../Internal/ApplicationBuilderTests.cs | 12 ++++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNetCore.Http/Internal/ApplicationBuilder.cs b/src/Microsoft.AspNetCore.Http/Internal/ApplicationBuilder.cs index 6b36842fbb..c4e6fd7f07 100644 --- a/src/Microsoft.AspNetCore.Http/Internal/ApplicationBuilder.cs +++ b/src/Microsoft.AspNetCore.Http/Internal/ApplicationBuilder.cs @@ -29,7 +29,7 @@ namespace Microsoft.AspNetCore.Builder.Internal private ApplicationBuilder(ApplicationBuilder builder) { - Properties = builder.Properties; + Properties = new CopyOnWriteDictionary(builder.Properties, EqualityComparer.Default); } public IServiceProvider ApplicationServices diff --git a/src/Microsoft.AspNetCore.Http/Microsoft.AspNetCore.Http.csproj b/src/Microsoft.AspNetCore.Http/Microsoft.AspNetCore.Http.csproj index 04e24f5e2c..f0163c501c 100644 --- a/src/Microsoft.AspNetCore.Http/Microsoft.AspNetCore.Http.csproj +++ b/src/Microsoft.AspNetCore.Http/Microsoft.AspNetCore.Http.csproj @@ -18,6 +18,7 @@ + diff --git a/test/Microsoft.AspNetCore.Http.Tests/Internal/ApplicationBuilderTests.cs b/test/Microsoft.AspNetCore.Http.Tests/Internal/ApplicationBuilderTests.cs index 3a1a4b1606..976d9bf7e1 100644 --- a/test/Microsoft.AspNetCore.Http.Tests/Internal/ApplicationBuilderTests.cs +++ b/test/Microsoft.AspNetCore.Http.Tests/Internal/ApplicationBuilderTests.cs @@ -19,5 +19,17 @@ namespace Microsoft.AspNetCore.Builder.Internal app.Invoke(httpContext); Assert.Equal(httpContext.Response.StatusCode, 404); } + + [Fact] + public void PropertiesDictionaryIsDistinctAfterNew() + { + var builder1 = new ApplicationBuilder(null); + builder1.Properties["test"] = "value1"; + + var builder2 = builder1.New(); + builder2.Properties["test"] = "value2"; + + Assert.Equal(builder1.Properties["test"], "value1"); + } } } \ No newline at end of file