Hosting API review # 2

1. Moving HostingUtilities and PipelineInstance into internal namespaces.
2. Renaming some properties in IHostingEnvironment
3. Renaming IHttpContextAccessor HttpContext into Value.

Addresses:
https://github.com/aspnet/Hosting/issues/159
https://github.com/aspnet/Hosting/issues/157
https://github.com/aspnet/Hosting/issues/161
This commit is contained in:
Praburaj 2015-02-27 11:29:38 -08:00
parent eb2887e5ef
commit 6bf5eabd9f
10 changed files with 15 additions and 11 deletions

View File

@ -9,8 +9,8 @@ namespace Microsoft.AspNet.Hosting
{ {
string EnvironmentName { get; set; } string EnvironmentName { get; set; }
string WebRoot { get; } string WebRootPath { get; }
IFileProvider WebRootFileProvider { get; set; } IFileProvider WebRootFileProvider { get; }
} }
} }

View File

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using Microsoft.AspNet.Hosting.Builder; using Microsoft.AspNet.Hosting.Builder;
using Microsoft.AspNet.Hosting.Internal;
using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Hosting.Server;
using Microsoft.AspNet.Hosting.Startup; using Microsoft.AspNet.Hosting.Startup;

View File

@ -3,6 +3,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNet.FileProviders; using Microsoft.AspNet.FileProviders;
using Microsoft.AspNet.Hosting.Internal;
using Microsoft.Framework.Runtime; using Microsoft.Framework.Runtime;
namespace Microsoft.AspNet.Hosting namespace Microsoft.AspNet.Hosting
@ -14,8 +15,8 @@ namespace Microsoft.AspNet.Hosting
public HostingEnvironment(IApplicationEnvironment appEnvironment, IEnumerable<IConfigureHostingEnvironment> configures) public HostingEnvironment(IApplicationEnvironment appEnvironment, IEnumerable<IConfigureHostingEnvironment> configures)
{ {
EnvironmentName = DefaultEnvironmentName; EnvironmentName = DefaultEnvironmentName;
WebRoot = HostingUtilities.GetWebRoot(appEnvironment.ApplicationBasePath); WebRootPath = HostingUtilities.GetWebRoot(appEnvironment.ApplicationBasePath);
WebRootFileProvider = new PhysicalFileProvider(WebRoot); WebRootFileProvider = new PhysicalFileProvider(WebRootPath);
foreach (var configure in configures) foreach (var configure in configures)
{ {
configure.Configure(this); configure.Configure(this);
@ -24,8 +25,8 @@ namespace Microsoft.AspNet.Hosting
public string EnvironmentName { get; set; } public string EnvironmentName { get; set; }
public string WebRoot { get; private set; } public string WebRootPath { get; private set; }
public IFileProvider WebRootFileProvider { get; set; } public IFileProvider WebRootFileProvider { get; private set; }
} }
} }

View File

@ -6,7 +6,7 @@ using System.IO;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
namespace Microsoft.AspNet.Hosting namespace Microsoft.AspNet.Hosting.Internal
{ {
public static class HostingUtilities public static class HostingUtilities
{ {

View File

@ -7,7 +7,7 @@ using Microsoft.AspNet.Builder;
using Microsoft.AspNet.FeatureModel; using Microsoft.AspNet.FeatureModel;
using Microsoft.AspNet.Hosting.Builder; using Microsoft.AspNet.Hosting.Builder;
namespace Microsoft.AspNet.Hosting namespace Microsoft.AspNet.Hosting.Internal
{ {
public class PipelineInstance : IDisposable public class PipelineInstance : IDisposable
{ {

View File

@ -4,6 +4,7 @@
using System; using System;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using Microsoft.AspNet.Hosting.Internal;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
namespace Microsoft.AspNet.Hosting.Server namespace Microsoft.AspNet.Hosting.Server

View File

@ -92,7 +92,7 @@ namespace Microsoft.AspNet.Hosting.Startup
{ {
if (string.IsNullOrEmpty(applicationName)) if (string.IsNullOrEmpty(applicationName))
{ {
throw new ArgumentException("applicationName"); throw new ArgumentException("Value cannot be null or empty.", "applicationName");
} }
var assembly = Assembly.Load(new AssemblyName(applicationName)); var assembly = Assembly.Load(new AssemblyName(applicationName));

View File

@ -60,7 +60,7 @@ namespace Microsoft.AspNet.Hosting
{ {
var services = HostingServices.Create().BuildServiceProvider(); var services = HostingServices.Create().BuildServiceProvider();
var env = services.GetRequiredService<IHostingEnvironment>(); var env = services.GetRequiredService<IHostingEnvironment>();
Assert.Equal(Path.GetFullPath("testroot"), env.WebRoot); Assert.Equal(Path.GetFullPath("testroot"), env.WebRootPath);
Assert.True(env.WebRootFileProvider.GetFileInfo("TextFile.txt").Exists); Assert.True(env.WebRootFileProvider.GetFileInfo("TextFile.txt").Exists);
} }

View File

@ -1,6 +1,7 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Hosting.Internal;
using Xunit; using Xunit;
namespace Microsoft.AspNet.Hosting.Tests namespace Microsoft.AspNet.Hosting.Tests

View File

@ -75,7 +75,7 @@ namespace Microsoft.AspNet.TestHost
TestServer server = TestServer.Create(app => TestServer server = TestServer.Create(app =>
{ {
var env = app.ApplicationServices.GetRequiredService<IHostingEnvironment>(); var env = app.ApplicationServices.GetRequiredService<IHostingEnvironment>();
Assert.Equal(Directory.GetCurrentDirectory(), env.WebRoot); Assert.Equal(Directory.GetCurrentDirectory(), env.WebRootPath);
}); });
} }