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

Commit

Permalink
Remove references to IRuntimeEnvironment \ IApplicationEnvironment
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavkm committed Apr 25, 2016
1 parent e874f99 commit 3853d98
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 45 deletions.
4 changes: 1 addition & 3 deletions src/Microsoft.AspNetCore.Hosting/Internal/WebHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.PlatformAbstractions;

namespace Microsoft.AspNetCore.Hosting.Internal
{
Expand Down Expand Up @@ -187,10 +186,9 @@ private RequestDelegate BuildApplication()
logger.ApplicationError(ex);

// Generate an HTML error page.
var runtimeEnv = _applicationServices.GetRequiredService<IRuntimeEnvironment>();
var hostingEnv = _applicationServices.GetRequiredService<IHostingEnvironment>();
var showDetailedErrors = hostingEnv.IsDevelopment() || _options.DetailedErrors;
var errorBytes = StartupExceptionPage.GenerateErrorHtml(showDetailedErrors, runtimeEnv, ex);
var errorBytes = StartupExceptionPage.GenerateErrorHtml(showDetailedErrors, ex);

return context =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal static class StartupExceptionPage
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();
Expand All @@ -48,7 +48,7 @@ public static byte[] GenerateErrorHtml(bool showDetails, IRuntimeEnvironment run
}

// 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));
Expand Down Expand Up @@ -230,8 +230,9 @@ private static void SplitTypeIntoPrefixAndFriendlyName(Type type, out string pre
}
}

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;
Expand Down
7 changes: 1 addition & 6 deletions src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
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;
Expand Down Expand Up @@ -177,8 +176,7 @@ private IServiceCollection BuildHostingServices()
{
_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;

Expand Down Expand Up @@ -219,9 +217,6 @@ private IServiceCollection BuildHostingServices()
// Ensure object pooling is available everywhere.
services.AddSingleton<ObjectPoolProvider, DefaultObjectPoolProvider>();

services.AddSingleton(defaultPlatformServices.Application);
services.AddSingleton(defaultPlatformServices.Runtime);

if (!string.IsNullOrEmpty(_options.ServerAssembly))
{
// Add the server
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,6 @@ public void DefaultApplicationNameToStartupAssemblyName()

var hostingEnv = host.Services.GetService<IHostingEnvironment>();
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]
Expand All @@ -456,9 +453,6 @@ public void DefaultApplicationNameToStartupType()

var hostingEnv = host.Services.GetService<IHostingEnvironment>();
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]
Expand All @@ -473,9 +467,6 @@ public void DefaultApplicationNameAndBasePathToStartupMethods()

var hostingEnv = host.Services.GetService<IHostingEnvironment>();
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]
Expand Down

0 comments on commit 3853d98

Please sign in to comment.