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)