From 520fc2b5fdee91c7bded01dbade2cfdf18ff412b Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Thu, 24 Sep 2015 17:09:29 -0700 Subject: [PATCH] Fixed stack overflow when setting RequestServices - Added tests --- .../RequestServicesContainerFeature.cs | 2 +- .../TestServerTests.cs | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerFeature.cs b/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerFeature.cs index 4edc13392b..6a0972fe58 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerFeature.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/RequestServicesContainerFeature.cs @@ -55,8 +55,8 @@ namespace Microsoft.AspNet.Hosting.Internal set { + _requestServices = value; _requestServicesSet = true; - RequestServices = value; } } diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index a41a9141f8..174b29c092 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -151,6 +151,31 @@ namespace Microsoft.AspNet.TestHost Assert.Equal("Success", result); } + [Fact] + public async Task CanSetCustomServiceProvider() + { + var server = TestServer.Create(app => + { + app.Run(context => + { + context.ApplicationServices = new ServiceCollection() + .AddTransient() + .BuildServiceProvider(); + + context.RequestServices = new ServiceCollection() + .AddTransient() + .BuildServiceProvider(); + + var s1 = context.ApplicationServices.GetRequiredService(); + var s2 = context.RequestServices.GetRequiredService(); + + return context.Response.WriteAsync("Success"); + }); + }); + string result = await server.CreateClient().GetStringAsync("/path"); + Assert.Equal("Success", result); + } + public class ReplaceServiceProvidersFeatureFilter : IStartupFilter, IServiceProvidersFeature { public ReplaceServiceProvidersFeatureFilter(IServiceProvider appServices, IServiceProvider requestServices) @@ -232,6 +257,7 @@ namespace Microsoft.AspNet.TestHost Assert.Equal("Success", result); } + public class EnsureApplicationServicesFilter : IStartupFilter { public Action Configure(Action next)