Complex object app settings in Azure Function
- Is this a correct approach to store the complex app settings in Azure Function?
This is still an open question: see this github issue asking exactly this
- How do I get BusinessUnitMapping configured in Azure Portal for the Function App that I have deployed?
My current preferred approach is to use the options pattern with a delegate that uses GetEnvironmentVariable which will work both locally and in Azure. The downside is that you can't create complex types in the local settings file itself, but your object can be as complex as you like.
A simple example:
In local.settings.json:
{
...
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
...
"SomeSection:Setting1": "abc",
"SomeSection:Setting2": "xyz",
},
...
}
In your startup:
services.Configure<MySettingsPoco>(o =>
{
o.Setting1 = Environment.GetEnvironmentVariable("SomeSection:Setting1");
o.Setting2 = Environment.GetEnvironmentVariable("SomeSection:Setting2");
});
Then in Azure you can create these settings as follows: