I try to bind a config section to a custom type. When binding the value SiteId is assigned, but not the other values, there’s three string properties that’s not set (Version, Email, Name).
Config:
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"Assets": {
"SiteId": 14,
"Version": "2.3.12",
"Email": "[email protected]",
"Name": "Creator framework"
}
}
AssetsConfig.cs:
public class AssetsConfig
{
private readonly IConfiguration _config;
public AssetsConfig(IConfiguration _config)
{
_config = raw;
}
public int SiteId { get; set; }
public string Culture { get; set; }
public IConfiguration Config => _config;
public string Version { get; }
public string Email { get; }
public string Name { get; }
public string ReleaseDate { get; }
}
Binding:
AssetsConfig cnf = new Assets.AssetsConfig(builder.Configuration);
builder.Configuration.Bind(AssetsStatics.ConfigSectionName, cnf);
_ = builder.Services
.AddOptions()
.Configure<IConfiguration>(builder.Configuration)
.AddSingleton(cnf);
Confing element (cnf) after binding:
{SL.Assets.AssetsConfig}
Config: Sections = 102
Culture: null
Email: null
Name: null
ReleaseDate: null
SiteId: 14
Version: null
_raw: Sections = 102
As you can see the property SiteId is assigned correctly, but not the others.
Any ideas?