diff --git a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs index ca52616b35..9ad73e964a 100644 --- a/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs +++ b/src/Microsoft.AspNet.Hosting/WebHostBuilder.cs @@ -75,7 +75,6 @@ namespace Microsoft.AspNet.Hosting services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddSingleton(); services.AddLogging(); var diagnosticSource = new DiagnosticListener("Microsoft.AspNet"); diff --git a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs index 06c21fc3f8..d34bc4f447 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs @@ -13,6 +13,7 @@ using Microsoft.AspNet.Hosting.Startup; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Http.Features.Internal; +using Microsoft.AspNet.Http.Internal; using Microsoft.AspNet.Testing.xunit; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -289,6 +290,10 @@ namespace Microsoft.AspNet.TestHost [Fact] public async Task CanAccessHttpContext() { + Action configureServices = services => + { + services.AddSingleton(); + }; TestServer server = TestServer.Create(app => { app.Run(context => @@ -296,7 +301,7 @@ namespace Microsoft.AspNet.TestHost var accessor = app.ApplicationServices.GetRequiredService(); return context.Response.WriteAsync("HasContext:"+(accessor.HttpContext != null)); }); - }); + }, configureServices); string result = await server.CreateClient().GetStringAsync("/path"); Assert.Equal("HasContext:True", result); @@ -315,6 +320,11 @@ namespace Microsoft.AspNet.TestHost [Fact] public async Task CanAddNewHostServices() { + Action configureServices = services => + { + services.AddSingleton(); + services.AddSingleton(); + }; TestServer server = TestServer.Create(app => { app.Run(context => @@ -322,8 +332,7 @@ namespace Microsoft.AspNet.TestHost var accessor = app.ApplicationServices.GetRequiredService(); return context.Response.WriteAsync("HasContext:" + (accessor.Accessor.HttpContext != null)); }); - }, - services => services.AddSingleton()); + }, configureServices); string result = await server.CreateClient().GetStringAsync("/path"); Assert.Equal("HasContext:True", result);