diff --git a/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs
index 90e89a9647..7efceb0ca8 100644
--- a/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs
+++ b/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs
@@ -17,6 +17,7 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Logging;
+using Microsoft.Extensions.ObjectPool;
using Microsoft.Extensions.PlatformAbstractions;
namespace Microsoft.AspNetCore.Hosting
@@ -135,7 +136,7 @@ namespace Microsoft.AspNetCore.Hosting
}
///
- /// Configure the provided which will be available as a hosting service.
+ /// Configure the provided which will be available as a hosting service.
///
/// The delegate that configures the .
/// The .
@@ -155,7 +156,7 @@ namespace Microsoft.AspNetCore.Hosting
var appEnvironment = hostingContainer.GetRequiredService();
var startupLoader = hostingContainer.GetRequiredService();
-
+
var contentRootPath = ResolveContentRootPath(_options.ContentRootPath, appEnvironment.ApplicationBasePath);
var applicationName = ResolveApplicationName() ?? appEnvironment.ApplicationName;
@@ -201,6 +202,9 @@ namespace Microsoft.AspNetCore.Hosting
// Conjure up a RequestServices
services.AddTransient();
+ // Ensure object pooling is available everywhere.
+ services.TryAddSingleton();
+
var defaultPlatformServices = PlatformServices.Default;
if (defaultPlatformServices.Application != null)
{
diff --git a/test/Microsoft.AspNetCore.Hosting.Tests/WebHostBuilderTests.cs b/test/Microsoft.AspNetCore.Hosting.Tests/WebHostBuilderTests.cs
index f2a9a1fd49..6667e5d79d 100644
--- a/test/Microsoft.AspNetCore.Hosting.Tests/WebHostBuilderTests.cs
+++ b/test/Microsoft.AspNetCore.Hosting.Tests/WebHostBuilderTests.cs
@@ -13,8 +13,8 @@ using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Http.Internal;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.ObjectPool;
using Microsoft.Extensions.PlatformAbstractions;
-using System.Reflection;
using Xunit;
namespace Microsoft.AspNetCore.Hosting
@@ -92,12 +92,29 @@ namespace Microsoft.AspNetCore.Hosting
using (host)
{
host.Start();
- var service = host.Services.GetServices();
- Assert.NotNull(service);
+ var services = host.Services.GetServices();
+ Assert.NotNull(services);
+ Assert.NotEmpty(services);
+
await AssertResponseContains(server.RequestDelegate, "Exception from constructor");
}
}
+ [Fact]
+ public void DefaultObjectPoolProvider_IsRegistered()
+ {
+ var server = new TestServer();
+ var host = CreateWebHostBuilder()
+ .UseServer(server)
+ .Configure(app => { })
+ .Build();
+ using (host)
+ {
+ host.Start();
+ Assert.IsType(host.Services.GetService());
+ }
+ }
+
[Fact]
public async Task StartupConfigureServicesThrows_Fallback()
{
@@ -333,7 +350,7 @@ namespace Microsoft.AspNetCore.Hosting
[Fact]
public void RelativeContentRootIsResolved()
{
- var contentRootNet451 = PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows ?
+ var contentRootNet451 = PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows ?
"testroot" : "../../../../test/Microsoft.AspNetCore.Hosting.Tests/testroot";
var host = new WebHostBuilder()