From 1fabc29e4ffee980d42f02fe218e851529dc2d67 Mon Sep 17 00:00:00 2001 From: TekH Date: Mon, 15 Dec 2025 15:51:31 +0100 Subject: [PATCH] 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. --- src/ReC.API/Program.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/ReC.API/Program.cs b/src/ReC.API/Program.cs index d574d53..dc657be 100644 --- a/src/ReC.API/Program.cs +++ b/src/ReC.API/Program.cs @@ -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 => {