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