Remove references to IRuntimeEnvironment \ IApplicationEnvironment

This commit is contained in:
Pranav K 2016-04-22 19:29:05 -07:00
parent e874f99791
commit 3853d988c2
5 changed files with 6 additions and 45 deletions

View File

@ -15,7 +15,6 @@ using Microsoft.AspNetCore.Http.Features;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.PlatformAbstractions;
namespace Microsoft.AspNetCore.Hosting.Internal namespace Microsoft.AspNetCore.Hosting.Internal
{ {
@ -187,10 +186,9 @@ namespace Microsoft.AspNetCore.Hosting.Internal
logger.ApplicationError(ex); logger.ApplicationError(ex);
// Generate an HTML error page. // Generate an HTML error page.
var runtimeEnv = _applicationServices.GetRequiredService<IRuntimeEnvironment>();
var hostingEnv = _applicationServices.GetRequiredService<IHostingEnvironment>(); var hostingEnv = _applicationServices.GetRequiredService<IHostingEnvironment>();
var showDetailedErrors = hostingEnv.IsDevelopment() || _options.DetailedErrors; var showDetailedErrors = hostingEnv.IsDevelopment() || _options.DetailedErrors;
var errorBytes = StartupExceptionPage.GenerateErrorHtml(showDetailedErrors, runtimeEnv, ex); var errorBytes = StartupExceptionPage.GenerateErrorHtml(showDetailedErrors, ex);
return context => return context =>
{ {

View File

@ -24,7 +24,7 @@ namespace Microsoft.AspNetCore.Hosting.Startup
private static readonly string _errorExceptionFormatString = GetResourceString("GenericError_Exception.html"); private static readonly string _errorExceptionFormatString = GetResourceString("GenericError_Exception.html");
private static readonly string _errorFooterFormatString = GetResourceString("GenericError_Footer.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 // Build the message for each error
var builder = new StringBuilder(); var builder = new StringBuilder();
@ -48,7 +48,7 @@ namespace Microsoft.AspNetCore.Hosting.Startup
} }
// Generate the footer // Generate the footer
var footer = showDetails ? GenerateFooterEncoded(runtimeEnvironment) : null; var footer = showDetails ? GenerateFooterEncoded() : null;
// And generate the full markup // And generate the full markup
return Encoding.UTF8.GetBytes(string.Format(CultureInfo.InvariantCulture, _errorPageFormatString, builder, rawExceptionDetails, footer)); 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); var runtimeType = HtmlEncodeAndReplaceLineBreaks(environment.RuntimeType);
#if NETCOREAPP1_0 || NETSTANDARD1_3 #if NETCOREAPP1_0 || NETSTANDARD1_3
var systemRuntimeAssembly = typeof(System.ComponentModel.DefaultValueAttribute).GetTypeInfo().Assembly; var systemRuntimeAssembly = typeof(System.ComponentModel.DefaultValueAttribute).GetTypeInfo().Assembly;

View File

@ -5,7 +5,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq;
using System.Reflection; using System.Reflection;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting.Builder; using Microsoft.AspNetCore.Hosting.Builder;
@ -177,8 +176,7 @@ namespace Microsoft.AspNetCore.Hosting
{ {
_options = new WebHostOptions(_config); _options = new WebHostOptions(_config);
var defaultPlatformServices = PlatformServices.Default; var appEnvironment = PlatformServices.Default.Application;
var appEnvironment = defaultPlatformServices.Application;
var contentRootPath = ResolveContentRootPath(_options.ContentRootPath, appEnvironment.ApplicationBasePath); var contentRootPath = ResolveContentRootPath(_options.ContentRootPath, appEnvironment.ApplicationBasePath);
var applicationName = ResolveApplicationName() ?? appEnvironment.ApplicationName; var applicationName = ResolveApplicationName() ?? appEnvironment.ApplicationName;
@ -219,9 +217,6 @@ namespace Microsoft.AspNetCore.Hosting
// Ensure object pooling is available everywhere. // Ensure object pooling is available everywhere.
services.AddSingleton<ObjectPoolProvider, DefaultObjectPoolProvider>(); services.AddSingleton<ObjectPoolProvider, DefaultObjectPoolProvider>();
services.AddSingleton(defaultPlatformServices.Application);
services.AddSingleton(defaultPlatformServices.Runtime);
if (!string.IsNullOrEmpty(_options.ServerAssembly)) if (!string.IsNullOrEmpty(_options.ServerAssembly))
{ {
// Add the server // Add the server

View File

@ -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;
}
}

View File

@ -439,9 +439,6 @@ namespace Microsoft.AspNetCore.Hosting
var hostingEnv = host.Services.GetService<IHostingEnvironment>(); var hostingEnv = host.Services.GetService<IHostingEnvironment>();
Assert.Equal("Microsoft.AspNetCore.Hosting.Tests", hostingEnv.ApplicationName); Assert.Equal("Microsoft.AspNetCore.Hosting.Tests", hostingEnv.ApplicationName);
var appEnv = host.Services.GetService<IApplicationEnvironment>();
Assert.Equal(PlatformServices.Default.Application.ApplicationName, appEnv.ApplicationName);
Assert.Equal(PlatformServices.Default.Application.ApplicationBasePath, appEnv.ApplicationBasePath);
} }
[Fact] [Fact]
@ -456,9 +453,6 @@ namespace Microsoft.AspNetCore.Hosting
var hostingEnv = host.Services.GetService<IHostingEnvironment>(); var hostingEnv = host.Services.GetService<IHostingEnvironment>();
Assert.Equal("Microsoft.AspNetCore.Hosting.Tests", hostingEnv.ApplicationName); Assert.Equal("Microsoft.AspNetCore.Hosting.Tests", hostingEnv.ApplicationName);
var appEnv = host.Services.GetService<IApplicationEnvironment>();
Assert.Equal(PlatformServices.Default.Application.ApplicationName, appEnv.ApplicationName);
Assert.Equal(PlatformServices.Default.Application.ApplicationBasePath, appEnv.ApplicationBasePath);
} }
[Fact] [Fact]
@ -473,9 +467,6 @@ namespace Microsoft.AspNetCore.Hosting
var hostingEnv = host.Services.GetService<IHostingEnvironment>(); var hostingEnv = host.Services.GetService<IHostingEnvironment>();
Assert.Equal("Microsoft.AspNetCore.Hosting.Tests", hostingEnv.ApplicationName); Assert.Equal("Microsoft.AspNetCore.Hosting.Tests", hostingEnv.ApplicationName);
var appEnv = host.Services.GetService<IApplicationEnvironment>();
Assert.Equal(PlatformServices.Default.Application.ApplicationName, appEnv.ApplicationName);
Assert.Equal(PlatformServices.Default.Application.ApplicationBasePath, appEnv.ApplicationBasePath);
} }
[Fact] [Fact]