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:
@@ -25,6 +25,13 @@ try
|
|||||||
|
|
||||||
var config = builder.Configuration;
|
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.
|
// Add services to the container.
|
||||||
builder.Services.AddRecServices(options =>
|
builder.Services.AddRecServices(options =>
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user