Table of Contents

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, IsProd static flags available anywhere
  • Environment name: reads from ASPNETCORE_ENVIRONMENT across 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:

  1. environmentConfig.json transformation file for current environment
  2. environmentConfig.json name property
  3. ASPNETCORE_ENVIRONMENT from mstest.runsettings, web.config, launchSettings.json or Windows environment variables
  4. Falls back to "" — never null

Caveats

  • IsDevelopment returns true if environment is unset or unrecognized — safe default but worth being aware of
  • Inherit EnvironmentConfig<YourClass, YourEnum> if you need additional properties beyond Name and EnvironmentType
  • ContentRootPath strips /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.