| | | 1 | | namespace ZhEaIsNsAaBn.ViewModels; |
| | | 2 | | |
| | | 3 | | /// <summary>Which environment the app runs in. Bind it from the <c>EnvironmentSettings</c> configuration section.</summ |
| | | 4 | | public class EnvironmentSettings |
| | | 5 | | { |
| | | 6 | | private const string DevelopmentName = "Development"; |
| | | 7 | | |
| | | 8 | | |
| | | 9 | | /// <summary> |
| | | 10 | | /// Creates the settings. <see cref="IsDevelopment"/> starts as <see langword="true"/> when the hosting environment |
| | | 11 | | /// <c>Development</c>: <c>ASPNETCORE_ENVIRONMENT</c>, or <c>DOTNET_ENVIRONMENT</c> if that isn't set (case-insensit |
| | | 12 | | /// same precedence as ASP.NET Core). Values bound from configuration override it. |
| | | 13 | | /// </summary> |
| | 36 | 14 | | public EnvironmentSettings() |
| | | 15 | | { |
| | 36 | 16 | | var environmentName = Environment.GetEnvironmentVariable( "ASPNETCORE_ENVIRONMENT" ) |
| | 36 | 17 | | ?? Environment.GetEnvironmentVariable( "DOTNET_ENVIRONMENT" ); |
| | | 18 | | |
| | | 19 | | |
| | 36 | 20 | | if ( string.Equals( environmentName, DevelopmentName, StringComparison.OrdinalIgnoreCase ) ) |
| | | 21 | | { |
| | 12 | 22 | | IsDevelopment = true; |
| | 12 | 23 | | IsProduction = false; |
| | | 24 | | } |
| | 36 | 25 | | } |
| | | 26 | | |
| | | 27 | | |
| | | 28 | | /// <summary>The configuration section name: <c>EnvironmentSettings</c>.</summary> |
| | 0 | 29 | | public static string SettingName => "EnvironmentSettings"; |
| | | 30 | | |
| | | 31 | | /// <summary>Whether the app runs in production.</summary> |
| | | 32 | | public bool IsProduction { get; set; } |
| | | 33 | | |
| | | 34 | | /// <summary>Whether the app runs in development. Checked before <see cref="IsProduction"/>.</summary> |
| | | 35 | | public bool IsDevelopment { get; set; } |
| | | 36 | | } |