Problem statement
Add the configuration sources back in the right order, so a setting comes from the base file, then the environment's own file, then an environment variable, with each one overriding the one before.
Requirements
Program calls ComposeConfigurationSources, which removes every default configuration source. Your task has one part: add the sources back in StatusPageApi/Configuration/ConfigurationComposition.cs.
Configuration sources are read in the order you add them, and a later source overrides the same key from an earlier one. The current environment name, such as Development or Staging, is in builder.Environment.EnvironmentName.
ConfigurationComposition
Add these three sources, in this order:
- appsettings.json, the base file
- appsettings.{EnvironmentName}.json, for example appsettings.Staging.json when the environment is Staging. Mark it optional: some environments, such as Production, have no file of their own, and the app must still start
- the environment variables. A variable such as StatusPage__WelcomeMessage (two underscores) sets the key StatusPage:WelcomeMessage
The settings files are provided, all under the StatusPage section:
- appsettings.json sets all three keys:
- WelcomeMessage: Welcome from the base settings file
- RefreshSeconds: 60
- SupportContact: support-base@example.com
- appsettings.Staging.json sets two keys:
- WelcomeMessage: Welcome from the staging settings file
- RefreshSeconds: 30
- appsettings.Demo.json sets one key:
- WelcomeMessage: Welcome from the demo settings file
ConfigController (provided)
- GET /config/effective answers 200 with welcomeMessage, refreshSeconds and supportContact, as the composed configuration resolves them
Sample Requests & Responses
GET /config/effective when the environment is Development, which has no StatusPage settings of its own
Response (200 OK):
{
"welcomeMessage": "Welcome from the base settings file",
"refreshSeconds": 60,
"supportContact": "support-base@example.com"
}
GET /config/effective when the environment is Staging
Response (200 OK):
{
"welcomeMessage": "Welcome from the staging settings file",
"refreshSeconds": 30,
"supportContact": "support-base@example.com"
}
GET /config/effective when the environment is Staging and StatusPage__WelcomeMessage is set to "Welcome from the environment variables"
Response (200 OK):
{
"welcomeMessage": "Welcome from the environment variables",
"refreshSeconds": 30,
"supportContact": "support-base@example.com"
}
