UPDATE: After some clearification, question is about changing environment vars run-time. That is not a very good idea. For sharing application-wide variables that may change, a cache is a viable solution.
In Startup#ConfigureServices
services.AddDistributedMemoryCache();
Then you can inject
IMemoryCache
into your code. You can add/change cache value like this
_cache.Set("myval", 123, DateTimeOffset.MaxValue);
and the value will stay in cache until end of time (or until your code changes/removes it). You fetch data from cache like this
var myVal = 0;
if (_cache.TryGetValue("myval", out int value))
{
myVal = value;
}
If you need to initialize the cache with some value from appsettings.json, that can be done inside Program#Main after webHost is built, and before calling webHost.Run / webHost.RunAsync.
END of update
Unless you have a class called AppSetting, json should look like below. You should have an appsettings.json that applies to all environments, an appsettings.Staging.json for staging, and an appsettings.Production.json for production.
{
"RabbitMqUrl": "rabbitmq://localhost/",
"RabbitMqUserName": "guest",
"RabbitMqPassword": "guest",
"LoginMessage": "x",
"ResetPasswordMessage": "x",
"myval": 10
}
You select running enviroment in Docker file like this
ENV ASPNETCORE_ENVIRONMENT Production
You can override parameters in appsettings.json like this
ENV ASPNETCORE_myval 123
If you stick with your original JSON structure:
ENV ASPNETCORE_AppSetting__myval 123