I am building an Azure Function and have a config that looks like this
{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"AzureWebJobsSecretStorageType": "files",
"SQLAZURECONNSTR_SqlConnection": "yyyy",
"SqlConnection": "zzzzz",
"QueueStorage": "xxxxxx"
},
"ErpConfiguration": {
"BaseUri": "https://localhost:7209/",
"CompanyDetail": {
"DaysInPastToCollect": 1,
"GetCount": {
"ItemsPerPage": 50,
"Endpoint": "xxxx/count"
},
"GetList": {
"Format": "json",
"StorageQueueName": "local-emulator",
"Endpoint": "xxxx",
"UrlFilters": {
"UseLastUpdatedDateFilter": true,
"UseFormatFilter": true,
"UsePaginationFilters": true,
"SelectedColumns": "CompCode, Lastupdateddate"
}
}
}
}
}
In Startup.cs I have a method that should be mapping like this
public static void AddConfig(this IServiceCollection services)
{
services
.AddOptions<ErpConfiguration>()
.Configure<IConfiguration>((settings, configuration) => { configuration.Bind("ErpConfiguration", settings); });
}
However, when running this and checking the config, in the service that looks like this
public CompanyCodeService(
IOptions<ErpConfiguration> erpConfiguration,
HttpClient client)
{
_erpConfiguration = erpConfiguration.Value;
_client = client;
_serializerSettings = new JsonSerializerSettings();
_serializerSettings.Converters.Add(new IsoDateTimeConverter());
_client.BaseAddress = _erpConfiguration.BaseUri;
}
The properties in erpConfiguration are null or set as the default values in the class.
I would be grateful if someone could tell me where I am going wrong and why the values are not being mapped correctly.
I have looked in places such as Read values from local.settings.json in VS 2017 Azure Function development
Add custom section to .NET Core local.settings.json
Ideally I dont want to have a pointer to my configs as when this is deployed this is coming from Azure App Configs