It seams that there is an issue when using MultiAppSettings with NetCoreAppSettings.
NetCoreAppSettings is working like expected but when wrapped inside MultiAppSettings, this will return always null or throw an exception.
The problem we have is with the Get<T>(string name) and Get<T>(string name, T deafultValue) methods
I’m not able to repro this, if the key exists I get the configured value with both Get APIs whether it’s the first provider in MultiAppSettings or last. If it doesn’t exist it returns the expected “DEFAULT”.
AppSettings = new MultiAppSettings(
AppSettings,
new DictionarySettings());
var existsGetOrDefault = AppSettings.Get("Exists", "DEFAULT");
var existsGet = AppSettings.Get<string>("Exists");
var notExists = AppSettings.Get("NotExists", "DEFAULT");
public interface IServerSettings
{
/// <summary>
/// Chiave-valore dei end point del server.
/// </summary>
Dictionary<string, UrlSettings> Endpoints { get; set; }
}
/// <summary>
/// Configurazione Url del server.
/// </summary>
public class ServerSettings : IServerSettings
{
/// <summary>
/// Chiave-valore dei end point del server.
/// </summary>
public Dictionary<string, UrlSettings> Endpoints { get; set; }
}
public interface IUrlSettings
{
/// <summary>
/// Il url. Url è del tipo: "http://0.0.0.0:80"
/// </summary>
string Url { get; set; }
}
/// <summary>
/// Configurazione Url.
/// </summary>
public class UrlSettings : IUrlSettings
{
/// <summary>
/// Il url. Url è del tipo: "http://0.0.0.0:80"
/// </summary>
public string Url { get; set; }
}
Program.cs
var configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", false)
.Build();
//load from appsettings.json
var jsonAppSettings = new NetCoreAppSettings(configuration);
//load from appsettings.config
var appSettingsXml = new AppSettings();
//combine jsonAppSettings and appSettingsXml
var appSettings = new MultiAppSettings(jsonAppSettings, appSettingsXml);
//works as expected, server.Endpoints["Http"].Url = "http://0.0.0.0:80"
var server = jsonAppSettings.Get<ServerSettings>("Server");
//server is null
server = appSettings.Get<ServerSettings>("Server");