Demo showing how to do environment specific configuration in .Net Core
In the EnvironmentConfig/Config
folder are three files:
- appsettings.json
- appsettings.Staging.CA.json
- appsettings.Staging.UK.json
The ConfigurationLoader
class is set up using the new ConfigurationBuilder
logic in .Net Core to load these files based on the programs arguments.
The appsettings.json
is the default, whilst any keys present in the overrides like appsettings.Staging.CA.json
will overwrite the defaults for us.
The arguments specifying which environment and tenant we are in are passed to the program, e.g:
dotnet run Staging CA
- .Net SDK 2.1.2 or higher: https://www.microsoft.com/net/learn/get-started/windows
Run the following in the EnvironmentConfig
project folder:
dotnet restore
dotnet build
Run the following in the EnvironmentConfig
project folder.
To use the default appsettings.json
config with no environment or tenant overrides, use:
dotnet run
To pass in the environment and tenant to override the default configuration, use:
dotnet run Staging CA