Skip to content
This repository was archived by the owner on Dec 19, 2018. It is now read-only.

Commit b06a844

Browse files
committed
Ensure an ObjectPoolProvider is registered
- e.g. take advantage of aspnet/HttpAbstractions#561 fix wherever cookies are used
1 parent 6c1247b commit b06a844

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using Microsoft.Extensions.DependencyInjection;
1818
using Microsoft.Extensions.DependencyInjection.Extensions;
1919
using Microsoft.Extensions.Logging;
20+
using Microsoft.Extensions.ObjectPool;
2021
using Microsoft.Extensions.PlatformAbstractions;
2122

2223
namespace Microsoft.AspNetCore.Hosting
@@ -135,7 +136,7 @@ public IWebHostBuilder Configure(Action<IApplicationBuilder> configureApp)
135136
}
136137

137138
/// <summary>
138-
/// Configure the provided <see cref="ILoggerFactory"/> which will be available as a hosting service.
139+
/// Configure the provided <see cref="ILoggerFactory"/> which will be available as a hosting service.
139140
/// </summary>
140141
/// <param name="configureLogging">The delegate that configures the <see cref="ILoggerFactory"/>.</param>
141142
/// <returns>The <see cref="IWebHostBuilder"/>.</returns>
@@ -155,7 +156,7 @@ public IWebHost Build()
155156

156157
var appEnvironment = hostingContainer.GetRequiredService<IApplicationEnvironment>();
157158
var startupLoader = hostingContainer.GetRequiredService<IStartupLoader>();
158-
159+
159160
var contentRootPath = ResolveContentRootPath(_options.ContentRootPath, appEnvironment.ApplicationBasePath);
160161
var applicationName = ResolveApplicationName() ?? appEnvironment.ApplicationName;
161162

@@ -201,6 +202,9 @@ private IServiceCollection BuildHostingServices()
201202
// Conjure up a RequestServices
202203
services.AddTransient<IStartupFilter, AutoRequestServicesStartupFilter>();
203204

205+
// Ensure object pooling is available everywhere.
206+
services.TryAddSingleton<ObjectPoolProvider, DefaultObjectPoolProvider>();
207+
204208
var defaultPlatformServices = PlatformServices.Default;
205209
if (defaultPlatformServices.Application != null)
206210
{

test/Microsoft.AspNetCore.Hosting.Tests/WebHostBuilderTests.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
using Microsoft.AspNetCore.Http.Internal;
1414
using Microsoft.Extensions.Configuration;
1515
using Microsoft.Extensions.DependencyInjection;
16+
using Microsoft.Extensions.ObjectPool;
1617
using Microsoft.Extensions.PlatformAbstractions;
17-
using System.Reflection;
1818
using Xunit;
1919

2020
namespace Microsoft.AspNetCore.Hosting
@@ -92,12 +92,29 @@ public async Task IApplicationLifetimeRegisteredEvenWhenStartupCtorThrows_Fallba
9292
using (host)
9393
{
9494
host.Start();
95-
var service = host.Services.GetServices<IApplicationLifetime>();
96-
Assert.NotNull(service);
95+
var services = host.Services.GetServices<IApplicationLifetime>();
96+
Assert.NotNull(services);
97+
Assert.NotEmpty(services);
98+
9799
await AssertResponseContains(server.RequestDelegate, "Exception from constructor");
98100
}
99101
}
100102

103+
[Fact]
104+
public void DefaultObjectPoolProvider_IsRegistered()
105+
{
106+
var server = new TestServer();
107+
var host = CreateWebHostBuilder()
108+
.UseServer(server)
109+
.Configure(app => { })
110+
.Build();
111+
using (host)
112+
{
113+
host.Start();
114+
Assert.IsType<DefaultObjectPoolProvider>(host.Services.GetService<ObjectPoolProvider>());
115+
}
116+
}
117+
101118
[Fact]
102119
public async Task StartupConfigureServicesThrows_Fallback()
103120
{
@@ -333,7 +350,7 @@ public void UseBasePathConfiguresBasePath()
333350
[Fact]
334351
public void RelativeContentRootIsResolved()
335352
{
336-
var contentRootNet451 = PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows ?
353+
var contentRootNet451 = PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows ?
337354
"testroot" : "../../../../test/Microsoft.AspNetCore.Hosting.Tests/testroot";
338355

339356
var host = new WebHostBuilder()

0 commit comments

Comments
 (0)