Configuration.bind not setting values

1 week ago 9
ARTICLE AD BOX

I have the following section in my appsettings:

"ExternalApiSettings": [ { "User": "Administrator", "Key": "From user secrets", "Roles": [ "Admin" ], "Controllers": [ "All" ] } ],

Which I am trying to bind to the Users property of the following class:

public static class ExternalApiSettings { public static IEnumerable<ExternalApiUser> Users { get; set; } = Array.Empty<ExternalApiUser>(); }

By using the following

builder.Configuration.GetSection("ExternalApiSettings").Bind(ExternalApiSettings.Users);

But when I access the ExternalApiSettings.Users, it always an empty array.

If I do

ExternalApiSettings.Users = configuration.GetSection(nameof(ExternalApiSettings)).Get<IEnumerable<ExternalApiUser>>();

The Users gets populated, so is there any reason for the bind not to work?

Also, all the other binds in my code work fine - eg

builder.Configuration.GetSection("Umbraco:CMS:Content:Error404Collection").Bind(SiteSettings.ErrorPageCollection); "Umbraco": { "CMS": { "Content": { "AllowEditInvariantFromNonDefault": true, "Error404Collection": [ { "Culture": "default", "ContentKey": "aff1fbee-5a34-4c89-a7b2-4bcdbf4a6529" } ], } } } public static class SiteSettings { public static IEnumerable<ErrorPageSettings> ErrorPageCollection { get; set; } = Array.Empty<ErrorPageSettings>(); }
Read Entire Article