From a0de7564e23ca973932d498511f3d3380bceeec1 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Tue, 29 Mar 2016 03:03:40 -0700 Subject: [PATCH] Small tweaks to hosting - Added some framework assemblies to stop VS from complaining - Call AddSingleton instead of TryAddSigleton since we're always first. - Remove the null check since these abstractions are never null now. - Moved comments --- .../RequestServicesContainerMiddleware.cs | 3 --- .../WebHostBuilder.cs | 21 ++++++++----------- src/Microsoft.AspNetCore.Hosting/project.json | 6 ++++++ 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Microsoft.AspNetCore.Hosting/Internal/RequestServicesContainerMiddleware.cs b/src/Microsoft.AspNetCore.Hosting/Internal/RequestServicesContainerMiddleware.cs index fffbd88a56..eec8e5ac2d 100644 --- a/src/Microsoft.AspNetCore.Hosting/Internal/RequestServicesContainerMiddleware.cs +++ b/src/Microsoft.AspNetCore.Hosting/Internal/RequestServicesContainerMiddleware.cs @@ -3,11 +3,8 @@ using System; using System.Threading.Tasks; -using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Http.Features.Internal; -using Microsoft.Extensions.DependencyInjection; namespace Microsoft.AspNetCore.Hosting.Internal { diff --git a/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs index ff5494b9d6..af249dabcf 100644 --- a/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs +++ b/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs @@ -15,7 +15,6 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Internal; 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; @@ -221,8 +220,11 @@ namespace Microsoft.AspNetCore.Hosting configureLogging(_loggerFactory); } - services.AddSingleton(_loggerFactory); //The configured ILoggerFactory is added as a singleton here. AddLogging below will not add an additional one. - services.AddLogging(); //This is required to add ILogger of T. + //The configured ILoggerFactory is added as a singleton here. AddLogging below will not add an additional one. + services.AddSingleton(_loggerFactory); + + //This is required to add ILogger of T. + services.AddLogging(); services.AddTransient(); @@ -239,17 +241,12 @@ namespace Microsoft.AspNetCore.Hosting services.AddTransient(); // Ensure object pooling is available everywhere. - services.TryAddSingleton(); + services.AddSingleton(); var defaultPlatformServices = PlatformServices.Default; - if (defaultPlatformServices.Application != null) - { - services.TryAddSingleton(defaultPlatformServices.Application); - } - if (defaultPlatformServices.Runtime != null) - { - services.TryAddSingleton(defaultPlatformServices.Runtime); - } + + services.AddSingleton(defaultPlatformServices.Application); + services.AddSingleton(defaultPlatformServices.Runtime); foreach (var configureServices in _configureServicesDelegates) { diff --git a/src/Microsoft.AspNetCore.Hosting/project.json b/src/Microsoft.AspNetCore.Hosting/project.json index 264fc8d40d..8b529b440d 100644 --- a/src/Microsoft.AspNetCore.Hosting/project.json +++ b/src/Microsoft.AspNetCore.Hosting/project.json @@ -38,6 +38,12 @@ "frameworkAssemblies": { "System.Runtime": { "type": "build" + }, + "System.ComponentModel": { + "type": "build" + }, + "System.IO": { + "type": "build" } } },