This is my class:
using System.Collections.Generic;
namespace WebsiteAPI.Models
{
public class CollectionInAppSettings
{
public IDictionary<string,string> SomeCollection { get; set; }
}
}
This is my AppSettings:
"CollectionInAppSettings": {
"SomeCollection": {
"Val1": "Some string",
"Val2": "Some string2"
}
}
This is what is in my startup.cs in the ConfigureServices Section:
services.Configure<CollectionInAppSettings>(Configuration.GetSection("CollectionInAppSettings"));
This is whats in a dummy HelloController:
private readonly IOptions<CollectionInAppSettings> _options;
public HelloController(IOptions<CollectionInAppSettings> options)
{
_options = options;
}
[HttpGet("[action]")]
public IActionResult IsUp()
{
return Ok(_options.Value);
}
When calling the endpoint:
https://localhost:4010/api/hello/isup
This is returned:
"someCollection":{"Val1":"Some string","Val2":"Some string2"}
Here is a link to some other solutions to this problem: Click here