Link to another json file in appsettings.json for ASP.NET kernel configuration

In the old days, using the XML configuration, you could include a partial configuration from another file, for example this :

<appSettings file="relative file name">
    <!-- Remaining configuration settings -->
</appSettings>

Now, in the core of ASP.NET I wanted to share some configuration in appsettings-Development.jsonas well, for example appsettings-Staging.json. Is something like <appSettings file="">also accessible via json configuration?

+4
source share
1 answer

You can add the mutliple configuration file in the Startup class:

public class Startup
{
    public Startup(IHostingEnvironment env)
    {
        var builder = new ConfigurationBuilder()
            .SetBasePath(env.ContentRootPath)
            .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
            .AddJsonFile("appsettings-Development.json", optional: false)
            .AddJsonFile("appsettings-Staging.json", optional: false)
            .AddEnvironmentVariables();
        Configuration = builder.Build();
    }

. : https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration  ...

+6

Source: https://habr.com/ru/post/1685099/


All Articles