Consider following appsettings.json:
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"NumberOfRetries": 5,
"Option1": "abc",
"Option2": "def"
}
In order to read NumberOfRetries following class can be used successfully:
public class AppSettings
{
public int NumberOfRetries { get; set; }
public string Option1 { get; set; }
public string Option2 { get; set; }
}
with following code in Startup.cs:
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddOptions();
services.Configure<AppSettings>(Configuration);
}
Now, let's say key name is Number.Of.Retries instead of NumberOfRetries- with periods in the middle.
How can the AppSetings class (or the approach itself) be modified to support that? Can't exactly put periods in property name.