VS2015 Pro, .NET Core, Web Application.
I'm trying to figure out how to get objects out of appsettings, that have nested objects. I can do it with single level objects by creating a POCO with simple types that match the config names. But with more complex objects, it's not working. I'm getting top level objects back, but they are coming back null. Here's what I have so far:
StartUp.ConfigureServices:
appsettings.json:
POCO APIContext:
Using Class:
So I get my three API objects back but they are all null. I don't know enough about the Configuration in Startup.cs to know what it's supposed to look like, but here it is.
Can I add more than two appsettings. json files in dotnet core? Of course, we can add and use multiple appsettings. json files in ASP.NET Core project.
There are two methods to retrieve our values, string dbConn = configuration. GetSection("MySettings"). GetSection("DbConnection").
The appsettings. json file is an application configuration file used to store configuration settings such as database connections strings, any application scope global variables, etc. If you open the ASP.NET Core appsettings. json file, then you see the following code by default which is created by visual studio.
Nested options are supported and successfully deserialized from appsettings.json
. However, fields instead of properties break built-in POCO object deserialization. With the properties the problem should disappear:
public API FirstAPI { get; set; }
public string Path { get; set; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With