Organize ASP.NET Core configuration into separate JSON files by concern (database, logging, services, etc.) and load them conditionally based on environment variables. Pass file names (without extensions) as parameters, and the library automatically loads base files plus environment-specific overrides (e.g., database.json + database.Production.json). Designed for containerized environments (Docker, Kubernetes) with mount paths. Optional encryption support for sensitive values. Follows SOLID principles with separate extension classes by responsibility.
$ dotnet add package Voyager.Configuration.MountPathThe extension for AspNetCore to organize JSON configuration.
The nuget allows reading the JSON configuration files from a path. The path can be used by an environment like Linux, Docker, or Kubernetes to update the content by a mounting mechanism. In providing the library by docker images you will gain the possibility to avoid publishing your sensitive data in an image repository.
The library menage configuration is supplied by the JSON files. Cooperate with the WebApplicationBuilder or HostApplicationBuilder. Linux mount mechanism can only work with folders so the config files have to be in that folder.
The best metod to see how it worsk is look to the thest project.
The default configuration
builder.ConfigureAppConfiguration((hostingConfiguration, config) =>
{
config.AddMountConfiguration(hostingConfiguration.HostingEnvironment.GetSettingsProvider());
});
The default configuration will work with the files structures:
YourAppFiles
|--bin
|--config
|--appsettings.json
|--appsettings.Development.json
It works in the way that from the folder config will load appsettings.json. The dotnet from the ASPNETCORE_ENVIRONMENT set his HostEnviroment variable, and if is setted with value: Development the program finds the appsettings.Development.json file and will use it to override previous settings.
The library is open for extensions so it is possible to modify behavior. At the first, it is possible to make the obligation to possess a hosting file:
builder.ConfigureAppConfiguration((hostingConfiguration, config) =>
{
config.AddMountConfiguration(hostingConfiguration.HostingEnvironment.GetSettingsProviderForce());
});
The second possibility is to override the class Voyager.Configuration.MountPath.SettingsProvider and use the instance in the AddMountConfiguration method.
Also is possible to use the AddMountConfiguration with the action that is can change all settings.
builder.ConfigureAppConfiguration((hostingConfiguration, config) =>
{
config.AddMountConfiguration(settings =>
{
settings.HostingName = "MyEnv";
settings.Optional = false;
});
});