Auto-load appsettings.*.json files at startup

Dynamically adds all appsettings.*.json files in the root directory to the configuration, excluding appsettings.Development.json and appsettings.migration.json. This streamlines configuration management by automatically including relevant environment or custom config files.
This commit is contained in:
2025-12-15 15:51:31 +01:00
parent 56fb34d987
commit 1fabc29e4f

View File

@@ -25,6 +25,13 @@ try
var config = builder.Configuration;
Directory
.GetFiles(builder.Environment.ContentRootPath, "appsettings.*.json", SearchOption.TopDirectoryOnly)
.Where(file => Path.GetFileName(file) != $"appsettings.Development.json")
.Where(file => Path.GetFileName(file) != $"appsettings.migration.json")
.ToList()
.ForEach(file => config.AddJsonFile(file, true, true));
// Add services to the container.
builder.Services.AddRecServices(options =>
{