Using the .NET Core Microsoft.Extensions.Configuration
is it possible to bind to a Configuration to an object that contains an array?
You can configure ExampleOption
with code in ConfigureServices
method:
public void ConfigureServices(IServiceCollection services)
{
services.Configure(myOptions =>
{
myOptions.Array = new int[] { 1, 2, 3 };
});
}
or if you want to use json configuration file
appsettings.json
:
{
"ExampleOption": {
"Array": [1,2,3]
}
}
ConfigureServices
:
public void ConfigureServices(IServiceCollection services)
{
services.Configure(Configuration.GetSection("ExampleOption"));
}