29 lines
No EOL
1 KiB
C#
29 lines
No EOL
1 KiB
C#
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
namespace Yavsc.Server.Helpers;
|
|
|
|
public static class ConfigHelpers
|
|
{
|
|
|
|
public static IConfigurationBuilder AddConfiguration(this WebApplicationBuilder builder, string appName)
|
|
{
|
|
if (string.IsNullOrEmpty(appName))
|
|
{
|
|
var rootConfig = builder.Configuration
|
|
.AddJsonFile($"appsettings.json", optional: false, reloadOnChange: false);
|
|
|
|
rootConfig.AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", optional: true, reloadOnChange: false);
|
|
|
|
return rootConfig.AddEnvironmentVariables();
|
|
}
|
|
|
|
var specRootConfig = builder.Configuration
|
|
.AddJsonFile($"appsettings-{appName}.json", optional: false, reloadOnChange: false);
|
|
|
|
specRootConfig.AddJsonFile($"appsettings-{appName}.{builder.Environment.EnvironmentName}.json", optional: true, reloadOnChange: false);
|
|
|
|
return specRootConfig.AddEnvironmentVariables();
|
|
|
|
}
|
|
} |