I want to use JSON configuration for my ASP.NET Core project, as documented here: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-2.2
My configuration is called like so:
config
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{commandConfig["Site"]}.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables();
In every appsettings.<site>.json, I could put this:
{
"Site": "siteName1"
}
But that seems like a waste. What I want is to put this in appsettings.json:
{
"Site": "$(Site)"
}
And have variable substitution replace $(Site) as appropriate.
Is anything like this possible?
$(Site)supposed to be substituted with?.SubstituteVariables(context);and pass in Site in the context mapping.Sitesettings, but also their log location (c:\logs\${Site}), their error email subject ([${Site}] Error Occurred), etc is painful. Better to specify those three once in theappsettings.json` exactly as I wrote in this comment than to manually substitute and maintain 20 site-specific files.config.EmailSubject.Replace("$(Site)", theNameOfThisSite)