EnvironmentConfig
Description
Provides environment detection and configuration based on ASPNETCORE_ENVIRONMENT. Inherits from Config<T> — supports the same file discovery, transformations and decryption.
Features
- Environment detection:
IsDevelopment,IsTest,IsProdstatic flags available anywhere - Environment name: reads from
ASPNETCORE_ENVIRONMENTacross all hosting models — IIS, IISExpress, Kestrel, Test Explorer, CLI - Typed environment enum: inherit
EnvironmentConfig<T, TEnum>to map environment name to your own enum - ContentRootPath: static path to the application root folder
Behavior
IsDevelopment is true when neither IsProd nor IsTest is true — it's the fallback, not an explicit check.
IsTest covers a broad range of non-production, non-development environments:
AT, Integration, PreProd, PreProduction, QA,
Sandbox, Stage, Staging, Test, UAT, UnitTest,
CI, ContinuousIntegration, Build
IsProd matches only Prod and Production.
Environment name resolution priority varies by hosting model but generally follows:
environmentConfig.jsontransformation file for current environmentenvironmentConfig.jsonnamepropertyASPNETCORE_ENVIRONMENTfrommstest.runsettings,web.config,launchSettings.jsonor Windows environment variables- Falls back to
""— never null
Caveats
IsDevelopmentreturnstrueif environment is unset or unrecognized — safe default but worth being aware of- Inherit
EnvironmentConfig<YourClass, YourEnum>if you need additional properties beyondNameandEnvironmentType ContentRootPathstrips/bin/and/lib/path segments automatically — returns the project root, not the build output folder
Tip
Use EnvironmentConfig.IsProd instead of string.Equals(env, "Production") — it handles both Prod and Production and is available globally without injection.