.Net Core Variable in appSettings.json for referencing other config values

Imagine the following file appSettings.json

:

{
   "GlobalSettings": {
        "BaseUrl": "http://example.com:5000"
    },
    "NavigationSettings": {
        "LoginUrl": "{GlobalSettings:BaseUrl}/Login"
    }
}

      

What I would like to do is automatically replace the value GlobalSettings:BaseUrl

with the value NavigationSettings:LoginUrl

. I know it can be used appSettings.{env}.json

to override certain keys, but that overrides the entire value, not just part of it.

I could work around this by using an extension method something like the following, but that would require the programmer to remember to call the extension method wherever they might want to replace the config value.

ReplaceConfigValues(this string input, IConfiguration config) { /*...*/ }

      

Can anyone suggest any alternative methods I could use, or are there some new .Net Core features that might be missing?

Even something like referencing the environment variable in the config value would be helpful, but I don't know how. For example.

"LoginUrl": "${ENV_GLOBAL_BASE_URL}/Login"

      

+3


source to share





All Articles