I have a C# function app written in .NET 6.0 and I want to read a collection of settings from the local.settings.json file. Here is my startup file that I want to read my settings so I can access them later in my application:
public class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
BindAndRegisterStronglyTypedConfig(builder);
}
private void BindAndRegisterStronglyTypedConfig(IFunctionsHostBuilder builder)
{
var products = new Products();
builder.GetContext().Configuration.Bind(nameof(Products), products);
builder.Services.AddSingleton(products);
}
}
Then in my local.settings.json file I have the products that I want to read:
{
"Values": {
"Products": [
{
"ProductId": "#",
"Title": "#"
},
{
"ProductId": "#",
"Title": "#"
}
]
}
}
The models the values should bind to:
public class Products
{
public readonly List<Product> products = new List<Product>();
}
public class Product
{
public string ProductId { get; set; }
public string Title { get; set; }
}
Anybody understand what I've done wrong, I get no error just a null value for collection?