17

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:

enter image description here

appsettings.json:

enter image description here

POCO APIContext:

enter image description here

Using Class:

enter image description here

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.

enter image description here

Ilya Chumakov
  • 23,161
  • 9
  • 86
  • 114
Steve Eggering
  • 759
  • 2
  • 9
  • 23

1 Answers1

20

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; }
netotz
  • 193
  • 1
  • 4
  • 12
Ilya Chumakov
  • 23,161
  • 9
  • 86
  • 114