2026-06-14 18:30:15 +01:00
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
|
|
|
|
|
namespace Yavsc.Server.Helpers;
|
|
|
|
|
|
|
|
|
|
public static class ConfigHelpers
|
|
|
|
|
{
|
2026-06-15 00:33:38 +01:00
|
|
|
|
2026-06-19 21:13:17 +01:00
|
|
|
public static IConfigurationBuilder AddConfiguration(this WebApplicationBuilder builder, string appName)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(appName))
|
2026-06-14 18:30:15 +01:00
|
|
|
{
|
|
|
|
|
var rootConfig = builder.Configuration
|
2026-06-19 21:13:17 +01:00
|
|
|
.AddJsonFile($"appsettings.json", optional: false, reloadOnChange: false);
|
2026-06-14 18:30:15 +01:00
|
|
|
|
2026-06-19 21:13:17 +01:00
|
|
|
rootConfig.AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", optional: true, reloadOnChange: false);
|
2026-06-14 04:55:18 +01:00
|
|
|
|
2026-06-19 21:13:17 +01:00
|
|
|
return rootConfig.AddEnvironmentVariables();
|
2026-06-14 18:30:15 +01:00
|
|
|
}
|
2026-06-19 21:13:17 +01:00
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
}
|
2026-06-14 18:30:15 +01:00
|
|
|
}
|