Merge pull request #275 from hishamco/dev
Shift 'Development' & 'Production' constants into 'EnvironmentName' class
This commit is contained in:
commit
dfe8c39fe0
|
|
@ -0,0 +1,11 @@
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
namespace Microsoft.AspNet.Hosting
|
||||||
|
{
|
||||||
|
public static class EnvironmentName
|
||||||
|
{
|
||||||
|
public static readonly string Development = "Development";
|
||||||
|
public static readonly string Production = "Production";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -9,9 +9,6 @@ namespace Microsoft.AspNet.Hosting
|
||||||
{
|
{
|
||||||
public static class HostingEnvironmentExtensions
|
public static class HostingEnvironmentExtensions
|
||||||
{
|
{
|
||||||
private const string DevelopmentEnvironmentName = "Development";
|
|
||||||
private const string ProductionEnvironmentName = "Production";
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks if the current hosting environment name is development.
|
/// Checks if the current hosting environment name is development.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -19,7 +16,7 @@ namespace Microsoft.AspNet.Hosting
|
||||||
/// <returns>True if the environment name is Development, otherwise false.</returns>
|
/// <returns>True if the environment name is Development, otherwise false.</returns>
|
||||||
public static bool IsDevelopment([NotNull]this IHostingEnvironment hostingEnvironment)
|
public static bool IsDevelopment([NotNull]this IHostingEnvironment hostingEnvironment)
|
||||||
{
|
{
|
||||||
return hostingEnvironment.IsEnvironment(DevelopmentEnvironmentName);
|
return hostingEnvironment.IsEnvironment(EnvironmentName.Development);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -29,7 +26,7 @@ namespace Microsoft.AspNet.Hosting
|
||||||
/// <returns>True if the environment name is Production, otherwise false.</returns>
|
/// <returns>True if the environment name is Production, otherwise false.</returns>
|
||||||
public static bool IsProduction([NotNull]this IHostingEnvironment hostingEnvironment)
|
public static bool IsProduction([NotNull]this IHostingEnvironment hostingEnvironment)
|
||||||
{
|
{
|
||||||
return hostingEnvironment.IsEnvironment(ProductionEnvironmentName);
|
return hostingEnvironment.IsEnvironment(EnvironmentName.Production);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,7 @@ namespace Microsoft.AspNet.Hosting
|
||||||
{
|
{
|
||||||
public class HostingEnvironment : IHostingEnvironment
|
public class HostingEnvironment : IHostingEnvironment
|
||||||
{
|
{
|
||||||
internal const string DefaultEnvironmentName = "Production";
|
public string EnvironmentName { get; set; } = Microsoft.AspNet.Hosting.EnvironmentName.Production;
|
||||||
|
|
||||||
public string EnvironmentName { get; set; } = DefaultEnvironmentName;
|
|
||||||
|
|
||||||
public string WebRootPath { get; set; }
|
public string WebRootPath { get; set; }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -146,7 +146,7 @@ namespace Microsoft.AspNet.Hosting
|
||||||
{
|
{
|
||||||
var engine = CreateBuilder().Build();
|
var engine = CreateBuilder().Build();
|
||||||
var env = engine.ApplicationServices.GetRequiredService<IHostingEnvironment>();
|
var env = engine.ApplicationServices.GetRequiredService<IHostingEnvironment>();
|
||||||
Assert.Equal("Production", env.EnvironmentName);
|
Assert.Equal(EnvironmentName.Production, env.EnvironmentName);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -199,7 +199,7 @@ namespace Microsoft.AspNet.Hosting
|
||||||
using (engine.Start())
|
using (engine.Start())
|
||||||
{
|
{
|
||||||
var env = engine.ApplicationServices.GetRequiredService<IHostingEnvironment>();
|
var env = engine.ApplicationServices.GetRequiredService<IHostingEnvironment>();
|
||||||
Assert.True(env.IsEnvironment("Production"));
|
Assert.True(env.IsEnvironment(EnvironmentName.Production));
|
||||||
Assert.True(env.IsEnvironment("producTion"));
|
Assert.True(env.IsEnvironment("producTion"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue