Ensure an `ObjectPoolProvider` is registered

- e.g. take advantage of aspnet/HttpAbstractions#561 fix wherever cookies are used
This commit is contained in:
Doug Bunting 2016-03-23 15:11:58 -07:00
parent 6c1247b30c
commit b06a84457d
2 changed files with 27 additions and 6 deletions

View File

@ -17,6 +17,7 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.ObjectPool;
using Microsoft.Extensions.PlatformAbstractions; using Microsoft.Extensions.PlatformAbstractions;
namespace Microsoft.AspNetCore.Hosting namespace Microsoft.AspNetCore.Hosting
@ -135,7 +136,7 @@ namespace Microsoft.AspNetCore.Hosting
} }
/// <summary> /// <summary>
/// Configure the provided <see cref="ILoggerFactory"/> which will be available as a hosting service. /// Configure the provided <see cref="ILoggerFactory"/> which will be available as a hosting service.
/// </summary> /// </summary>
/// <param name="configureLogging">The delegate that configures the <see cref="ILoggerFactory"/>.</param> /// <param name="configureLogging">The delegate that configures the <see cref="ILoggerFactory"/>.</param>
/// <returns>The <see cref="IWebHostBuilder"/>.</returns> /// <returns>The <see cref="IWebHostBuilder"/>.</returns>
@ -155,7 +156,7 @@ namespace Microsoft.AspNetCore.Hosting
var appEnvironment = hostingContainer.GetRequiredService<IApplicationEnvironment>(); var appEnvironment = hostingContainer.GetRequiredService<IApplicationEnvironment>();
var startupLoader = hostingContainer.GetRequiredService<IStartupLoader>(); var startupLoader = hostingContainer.GetRequiredService<IStartupLoader>();
var contentRootPath = ResolveContentRootPath(_options.ContentRootPath, appEnvironment.ApplicationBasePath); var contentRootPath = ResolveContentRootPath(_options.ContentRootPath, appEnvironment.ApplicationBasePath);
var applicationName = ResolveApplicationName() ?? appEnvironment.ApplicationName; var applicationName = ResolveApplicationName() ?? appEnvironment.ApplicationName;
@ -201,6 +202,9 @@ namespace Microsoft.AspNetCore.Hosting
// Conjure up a RequestServices // Conjure up a RequestServices
services.AddTransient<IStartupFilter, AutoRequestServicesStartupFilter>(); services.AddTransient<IStartupFilter, AutoRequestServicesStartupFilter>();
// Ensure object pooling is available everywhere.
services.TryAddSingleton<ObjectPoolProvider, DefaultObjectPoolProvider>();
var defaultPlatformServices = PlatformServices.Default; var defaultPlatformServices = PlatformServices.Default;
if (defaultPlatformServices.Application != null) if (defaultPlatformServices.Application != null)
{ {

View File

@ -13,8 +13,8 @@ using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Http.Internal; using Microsoft.AspNetCore.Http.Internal;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.ObjectPool;
using Microsoft.Extensions.PlatformAbstractions; using Microsoft.Extensions.PlatformAbstractions;
using System.Reflection;
using Xunit; using Xunit;
namespace Microsoft.AspNetCore.Hosting namespace Microsoft.AspNetCore.Hosting
@ -92,12 +92,29 @@ namespace Microsoft.AspNetCore.Hosting
using (host) using (host)
{ {
host.Start(); host.Start();
var service = host.Services.GetServices<IApplicationLifetime>(); var services = host.Services.GetServices<IApplicationLifetime>();
Assert.NotNull(service); Assert.NotNull(services);
Assert.NotEmpty(services);
await AssertResponseContains(server.RequestDelegate, "Exception from constructor"); 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<DefaultObjectPoolProvider>(host.Services.GetService<ObjectPoolProvider>());
}
}
[Fact] [Fact]
public async Task StartupConfigureServicesThrows_Fallback() public async Task StartupConfigureServicesThrows_Fallback()
{ {
@ -333,7 +350,7 @@ namespace Microsoft.AspNetCore.Hosting
[Fact] [Fact]
public void RelativeContentRootIsResolved() 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"; "testroot" : "../../../../test/Microsoft.AspNetCore.Hosting.Tests/testroot";
var host = new WebHostBuilder() var host = new WebHostBuilder()