Quantcast
Channel: User Pure.Krome - Stack Overflow
Viewing all articles
Browse latest Browse all 74

Does ASP.NET Core allow you to read in the ENTIRE appsettings.json in a single call into a single class?

$
0
0

I've been manually reading all the sections of my Configuration (e.g. appsettings.json, env vars, secrets, etc) by reading in each "section", one by one. Works great.

But is it possible to just provide a single class (which has 'child' properties, representing each section, etc) and load the configuration values into this in a single call?

Here's an example of what I can do, section by section:

public class DatabaseSettings{    public const string DatabaseSettingsSectionKey = "Databases";    public string SqlServerConnectionString { get; set; }    public string AzureStorageConnectionString { get; set; }}public class <next section> { .. }public class <another section> { .. }public class <'n' section> { .. }public static IServiceCollection AddConfigurationOptions(this IServiceCollection services){    var databaseSettings = services        .AddOptions<DatabaseSettings>()        .Configure<IConfiguration>((settings, configuration) =>        {            configuration                .GetSection(DatabaseSettings.DatabaseSettingsSectionKey)                .Bind(settings);        })        .ValidateOnStart();    // Load section 2    // Load section 3    // Load section 'n'    ...    return services;}

Instead I would like to do:

public class ApplicationSettings{    public DatabaseSettings Databases { get; set; }    public NextSettings Nexts { get; set; }    public AnotherSettings Anothers { get; set; }    ....}

Is this possible?


Viewing all articles
Browse latest Browse all 74

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>