I'm trying to read config data from appsettings.json, which looks like this:
{
Owner: {
Name: "Dave",
City: "Dusseldorf"
}
}
In Startup.cs I have:
public Startup(IConfiguration configuration)
{
var builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json");
Configuration = builder.Build();
}
In my class I have
private readonly IConfiguration _configuration;
public MyClass(
IConfiguration configuration
)
{
_configuration = configuration;
}
...and later in the same class
string name= _configuration["Owner.Name"];
But this is always empty.
However, if I add a breakpoint on that line and expand the _configuration class I can see a list of Providers (Count = 5) including one for appsettings.json, and if I expand this I can see my setting values, including Name.
However these don't seem to be accessible from code.
Am I using the wrong class/namespace? How should I read these values?