I have an appsettings.json and appsettings.Development.json. I need to assign the SmtpServer name depending on the environment.
The config file in appsettings.json is:
{
"EmailConfiguration": {
"SmtpServer": "mail.MYDOMAIN.com"
}
}
And in appsettings.Development.json is:
{
"EmailConfiguration": {
"SmtpServer": "mail.MYLOCAL.com"
}
}
When I assign the configuration in Startup ConfigureServices() like such:
var emailconfig = Configuration.GetSection("EmailConfiguration").Get<EmailConfiguration>();
services.AddSingleton<IEmailConfiguration>(emailconfig);
It always uses appsettings.json ('mail.MYDOMAIN.com') and NOT appsettings.Development.json.
How do I modify this code to use the correct environment settings?
The answer is that all I needed was the environment variables in the 2 different appsettings files. My problem was a missing closing bracket in one of my configuration settings which meant that the appsettings.Development.json would not replace appsettings.json variables since they didn't match. Oops.....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With