World-class .NET Contractor. Top 1% on Stack Overflow. Top 3% of Freelance Developers. 9 Microsoft MVP Awards. My clients call me the Coding Machine. :)
To get array values from appSettings.json you could use typed settings class like this:
public class SampleBook
{
public int Id { get; set; }
public string Name { get; set; }
}
public class AppSettings
{
public string SampleText { get; set; }
public int SampleNumber { get; set; }
public bool SampleBoolean { get; set; }
public List<string> SampleArray { get; set; }
public SampleBook SampleBook { get; set; }
public List<SampleBook> SampleBooks { get; set; }
public SampleBook NullSample { get; set; }
}
... and initialize it using Microsoft.Extensions.DependencyInjection package via OptionsConfigurationServiceCollectionExtensions with this line of code
services.Configure<AppSettings>(configuration);
where configuration is IConfiguration and services - IServiceCollection
To get array values from appSettings.json you could use typed settings class like this:
... and initialize it using Microsoft.Extensions.DependencyInjection package via OptionsConfigurationServiceCollectionExtensions with this line of code
where configuration is IConfiguration and services - IServiceCollection
Hope that helps!
Digitally yours, the Coding-Machine.NET
Thank you for your great comment!
I will try your suggestion on my next ASP NET Core project :)