I have a console application and want to configure my Options by mapping the configuration from the appsettings.json file to a custom class. Packages I installed so far
- Microsoft.Extensions.Configuration v5.0.0
- Microsoft.Extensions.DependencyInjection v5.0.1
- Microsoft.Extensions.Options v5.0.0
Given this sample class
public class MyOptions
{
public string Foo { get; set; }
}
and this configuration
{
"myOptions": {
"foo": "bar"
}
}
I'm trying to map it with this code
public void ConfigureOptions(IServiceCollection serviceCollection)
{
IServiceProvider serviceProvider = serviceCollection.BuildServiceProvider();
IConfiguration configuration = serviceProvider.GetService<IConfiguration>();
IConfigurationSection myConfigurationSection = configuration.GetSection("MyOptions");
serviceCollection.Configure<MyOptions>(myConfigurationSection);
}
Unfortunately this is invalid syntax. It is not possible to pass in the section to the Configure method anymore.
Argument type 'Microsoft.Extensions.Configuration.IConfigurationSection' is not assignable to parameter type 'System.Action<MyApp.MyOptions>'
This confuses me since there is a similar example in the docs
Does someone know if I'm missing something?
