How do I convert from IConfigurationSection to generic list of strings? I wish to add a list of emails to code read from appsettings.json. The .Get<List>(); isn’t working. I’m not picking up how to do this from the microsoft documentation on IConfigurationSection.
EmailService.cs
public class EmailService : IEmailService
{
private readonly IConfiguration _configuration;
public EmailService(IConfiguration configuration)
{
_configuration = configuration;
}
public Task<IEnumerable<string>> GetDistributionWhitelist()
{
var emails = _configuration.GetSection("DistributionWhitelist:Emails").Get<List<string>>();
return emails;
}
}
appsettings.json
"DistributionWhitelist": {
"Emails": [
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]"
]
}