From 3853d988c2b6193a6d798e5cfbe1b027897b93fe Mon Sep 17 00:00:00 2001 From: Pranav K Date: Fri, 22 Apr 2016 19:29:05 -0700 Subject: [PATCH] Remove references to IRuntimeEnvironment \ IApplicationEnvironment --- .../Internal/WebHost.cs | 4 +--- .../Startup/StartupExceptionPage.cs | 7 +++--- .../WebHostBuilder.cs | 7 +----- .../Fakes/RuntimeEnvironment.cs | 24 ------------------- .../WebHostBuilderTests.cs | 9 ------- 5 files changed, 6 insertions(+), 45 deletions(-) delete mode 100644 test/Microsoft.AspNetCore.Hosting.Tests/Fakes/RuntimeEnvironment.cs diff --git a/src/Microsoft.AspNetCore.Hosting/Internal/WebHost.cs b/src/Microsoft.AspNetCore.Hosting/Internal/WebHost.cs index 54745fb505..237c3b7cf6 100644 --- a/src/Microsoft.AspNetCore.Hosting/Internal/WebHost.cs +++ b/src/Microsoft.AspNetCore.Hosting/Internal/WebHost.cs @@ -15,7 +15,6 @@ using Microsoft.AspNetCore.Http.Features; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.PlatformAbstractions; namespace Microsoft.AspNetCore.Hosting.Internal { @@ -187,10 +186,9 @@ namespace Microsoft.AspNetCore.Hosting.Internal logger.ApplicationError(ex); // Generate an HTML error page. - var runtimeEnv = _applicationServices.GetRequiredService(); var hostingEnv = _applicationServices.GetRequiredService(); var showDetailedErrors = hostingEnv.IsDevelopment() || _options.DetailedErrors; - var errorBytes = StartupExceptionPage.GenerateErrorHtml(showDetailedErrors, runtimeEnv, ex); + var errorBytes = StartupExceptionPage.GenerateErrorHtml(showDetailedErrors, ex); return context => { diff --git a/src/Microsoft.AspNetCore.Hosting/Startup/StartupExceptionPage.cs b/src/Microsoft.AspNetCore.Hosting/Startup/StartupExceptionPage.cs index cea0261b6d..8943cf56fb 100644 --- a/src/Microsoft.AspNetCore.Hosting/Startup/StartupExceptionPage.cs +++ b/src/Microsoft.AspNetCore.Hosting/Startup/StartupExceptionPage.cs @@ -24,7 +24,7 @@ namespace Microsoft.AspNetCore.Hosting.Startup private static readonly string _errorExceptionFormatString = GetResourceString("GenericError_Exception.html"); private static readonly string _errorFooterFormatString = GetResourceString("GenericError_Footer.html"); - public static byte[] GenerateErrorHtml(bool showDetails, IRuntimeEnvironment runtimeEnvironment, Exception exception) + public static byte[] GenerateErrorHtml(bool showDetails, Exception exception) { // Build the message for each error var builder = new StringBuilder(); @@ -48,7 +48,7 @@ namespace Microsoft.AspNetCore.Hosting.Startup } // Generate the footer - var footer = showDetails ? GenerateFooterEncoded(runtimeEnvironment) : null; + var footer = showDetails ? GenerateFooterEncoded() : null; // And generate the full markup return Encoding.UTF8.GetBytes(string.Format(CultureInfo.InvariantCulture, _errorPageFormatString, builder, rawExceptionDetails, footer)); @@ -230,8 +230,9 @@ namespace Microsoft.AspNetCore.Hosting.Startup } } - private static string GenerateFooterEncoded(IRuntimeEnvironment environment) + private static string GenerateFooterEncoded() { + var environment = PlatformServices.Default.Runtime; var runtimeType = HtmlEncodeAndReplaceLineBreaks(environment.RuntimeType); #if NETCOREAPP1_0 || NETSTANDARD1_3 var systemRuntimeAssembly = typeof(System.ComponentModel.DefaultValueAttribute).GetTypeInfo().Assembly; diff --git a/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs index 57168deaa1..88cd1c76fb 100644 --- a/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs +++ b/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; -using System.Linq; using System.Reflection; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting.Builder; @@ -177,8 +176,7 @@ namespace Microsoft.AspNetCore.Hosting { _options = new WebHostOptions(_config); - var defaultPlatformServices = PlatformServices.Default; - var appEnvironment = defaultPlatformServices.Application; + var appEnvironment = PlatformServices.Default.Application; var contentRootPath = ResolveContentRootPath(_options.ContentRootPath, appEnvironment.ApplicationBasePath); var applicationName = ResolveApplicationName() ?? appEnvironment.ApplicationName; @@ -219,9 +217,6 @@ namespace Microsoft.AspNetCore.Hosting // Ensure object pooling is available everywhere. services.AddSingleton(); - services.AddSingleton(defaultPlatformServices.Application); - services.AddSingleton(defaultPlatformServices.Runtime); - if (!string.IsNullOrEmpty(_options.ServerAssembly)) { // Add the server diff --git a/test/Microsoft.AspNetCore.Hosting.Tests/Fakes/RuntimeEnvironment.cs b/test/Microsoft.AspNetCore.Hosting.Tests/Fakes/RuntimeEnvironment.cs deleted file mode 100644 index 05cdeea772..0000000000 --- a/test/Microsoft.AspNetCore.Hosting.Tests/Fakes/RuntimeEnvironment.cs +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Microsoft.Extensions.PlatformAbstractions; - -namespace Microsoft.AspNetCore.Hosting.Fakes -{ - public class RuntimeEnvironment : IRuntimeEnvironment - { - public string OperatingSystem { get; } = "TestOs"; - - public string OperatingSystemVersion { get; } = "TestOsVersion"; - - public string RuntimeArchitecture { get; } = "TestArch"; - - public string RuntimeType { get; } = "TestRuntime"; - - public string RuntimeVersion { get; } = "TestRuntimeVersion"; - - public string RuntimePath { get; } = "TestRuntimePath"; - - public Platform OperatingSystemPlatform => Platform.Unknown; - } -} diff --git a/test/Microsoft.AspNetCore.Hosting.Tests/WebHostBuilderTests.cs b/test/Microsoft.AspNetCore.Hosting.Tests/WebHostBuilderTests.cs index afe4384b65..ce5d4fb8a4 100644 --- a/test/Microsoft.AspNetCore.Hosting.Tests/WebHostBuilderTests.cs +++ b/test/Microsoft.AspNetCore.Hosting.Tests/WebHostBuilderTests.cs @@ -439,9 +439,6 @@ namespace Microsoft.AspNetCore.Hosting var hostingEnv = host.Services.GetService(); Assert.Equal("Microsoft.AspNetCore.Hosting.Tests", hostingEnv.ApplicationName); - var appEnv = host.Services.GetService(); - Assert.Equal(PlatformServices.Default.Application.ApplicationName, appEnv.ApplicationName); - Assert.Equal(PlatformServices.Default.Application.ApplicationBasePath, appEnv.ApplicationBasePath); } [Fact] @@ -456,9 +453,6 @@ namespace Microsoft.AspNetCore.Hosting var hostingEnv = host.Services.GetService(); Assert.Equal("Microsoft.AspNetCore.Hosting.Tests", hostingEnv.ApplicationName); - var appEnv = host.Services.GetService(); - Assert.Equal(PlatformServices.Default.Application.ApplicationName, appEnv.ApplicationName); - Assert.Equal(PlatformServices.Default.Application.ApplicationBasePath, appEnv.ApplicationBasePath); } [Fact] @@ -473,9 +467,6 @@ namespace Microsoft.AspNetCore.Hosting var hostingEnv = host.Services.GetService(); Assert.Equal("Microsoft.AspNetCore.Hosting.Tests", hostingEnv.ApplicationName); - var appEnv = host.Services.GetService(); - Assert.Equal(PlatformServices.Default.Application.ApplicationName, appEnv.ApplicationName); - Assert.Equal(PlatformServices.Default.Application.ApplicationBasePath, appEnv.ApplicationBasePath); } [Fact]