Voyager.Configuration.MountPath 1.3.0-preview.2

This is a prerelease version of Voyager.Configuration.MountPath.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Voyager.Configuration.MountPath --version 1.3.0-preview.2
                    
NuGet\Install-Package Voyager.Configuration.MountPath -Version 1.3.0-preview.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Voyager.Configuration.MountPath" Version="1.3.0-preview.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Voyager.Configuration.MountPath" Version="1.3.0-preview.2" />
                    
Directory.Packages.props
<PackageReference Include="Voyager.Configuration.MountPath" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Voyager.Configuration.MountPath --version 1.3.0-preview.2
                    
#r "nuget: Voyager.Configuration.MountPath, 1.3.0-preview.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Voyager.Configuration.MountPath@1.3.0-preview.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Voyager.Configuration.MountPath&version=1.3.0-preview.2&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Voyager.Configuration.MountPath&version=1.3.0-preview.2&prerelease
                    
Install as a Cake Tool

Voyager.Configuration.MountPath

NuGet License

An ASP.NET Core extension for organizing JSON configuration files with support for environment-specific settings, encrypted values, and Docker/Kubernetes mount paths.

About

This library provides a simple way to organize JSON configuration files by file name (without extensions) and load them conditionally based on environment variables. Designed for containerized environments like Docker and Kubernetes, it allows you to:

  • Organize configuration by concern: Separate files for database, logging, services, etc.
  • Load files conditionally: Automatically loads environment-specific variants (e.g., database.json + database.Production.json)
  • Mount at runtime: Keep configuration outside container images using volume mounts
  • Update without rebuilding: Change configuration without rebuilding or redeploying
  • Optional encryption: Encrypt sensitive values when needed (extension feature)

Features

  • ๐Ÿ“ File-based organization: Pass file names (without extensions) as parameters
  • ๐ŸŽฏ Conditional loading: Automatic environment-based file selection
  • ๐Ÿณ Container-friendly: Mount configuration from external volumes
  • ๐Ÿ”„ Hot reload: Automatically reload when configuration files change
  • ๐Ÿ”’ Optional encryption: Encrypt sensitive values (extension feature)
  • ๐Ÿ”Œ Dependency Injection: Full DI support with interfaces
  • ๐Ÿ—๏ธ SOLID architecture: Interface-based design for testability
  • ๐Ÿ“ฆ Multi-targeting: Supports .NET 4.8, .NET Core 3.1, .NET 6.0, and .NET 8.0

Installation

dotnet add package Voyager.Configuration.MountPath

Quick Start

Basic Usage: Single Configuration File

Pass file names (without .json extension) as parameters:

using Microsoft.Extensions.DependencyInjection;

var builder = Host.CreateDefaultBuilder(args);

builder.ConfigureAppConfiguration((context, config) =>
{
    var provider = context.HostingEnvironment.GetSettingsProvider();

    // Loads: appsettings.json + appsettings.{Environment}.json
    config.AddMountConfiguration(provider, "appsettings");
});

File structure:

YourApp/
โ”œโ”€โ”€ bin/
โ”‚   โ””โ”€โ”€ config/
โ”‚       โ”œโ”€โ”€ appsettings.json           # Base configuration
โ”‚       โ””โ”€โ”€ appsettings.Production.json # Environment-specific overrides

How it works:

  1. Loads base file: appsettings.json (required)
  2. Loads environment file: appsettings.{ASPNETCORE_ENVIRONMENT}.json (optional by default)
  3. Environment-specific values override base values

Customizing Settings

Configure custom mount paths or require environment-specific files:

builder.ConfigureAppConfiguration((context, config) =>
{
    config.AddMountConfiguration(settings =>
    {
        settings.FileName = "myconfig";           // File name without extension
        settings.ConfigMountPath = "configuration"; // Default: "config"
        settings.HostingName = "Production";      // Override environment detection
        settings.Optional = false;                // Require environment file
    });
});

Require environment-specific file:

builder.ConfigureAppConfiguration((context, config) =>
{
    // Throws exception if appsettings.Production.json doesn't exist
    config.AddMountConfiguration(context.HostingEnvironment.GetSettingsProviderForce());
});

Organizing Configuration by Concern

The key feature: organize configuration into separate files by concern, each loaded conditionally based on environment:

builder.ConfigureAppConfiguration((context, config) =>
{
    var provider = context.HostingEnvironment.GetSettingsProvider();

    // Each file name is loaded as: {name}.json + {name}.{Environment}.json
    config.AddMountConfiguration(provider, "appsettings");  // App settings
    config.AddMountConfiguration(provider, "database");     // Database config
    config.AddMountConfiguration(provider, "logging");      // Logging config
    config.AddMountConfiguration(provider, "services");     // External services
});

File structure:

config/
โ”œโ”€โ”€ appsettings.json
โ”œโ”€โ”€ appsettings.Production.json
โ”œโ”€โ”€ database.json
โ”œโ”€โ”€ database.Production.json
โ”œโ”€โ”€ logging.json
โ”œโ”€โ”€ logging.Production.json
โ”œโ”€โ”€ services.json
โ””โ”€โ”€ services.Production.json

Benefits:

  • Separation of concerns: Each file handles one aspect of configuration
  • Conditional loading: Different values for Development, Production, Staging, etc.
  • Easier management: Update only relevant files without touching others

Docker and Kubernetes Examples

Docker Example

Mount configuration files at runtime to separate concerns:

Dockerfile:

FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
COPY bin/Release/net8.0/publish .

# Configuration will be mounted at runtime
ENTRYPOINT ["dotnet", "YourApp.dll"]

docker-compose.yml:

services:
  myapp:
    image: myapp:latest
    volumes:
      - ./config:/app/config:ro  # Mount config folder
    environment:
      - ASPNETCORE_ENVIRONMENT=Production

config/ directory:

config/
โ”œโ”€โ”€ database.json              # Base database config
โ”œโ”€โ”€ database.Production.json   # Production overrides
โ”œโ”€โ”€ logging.json               # Base logging config
โ””โ”€โ”€ logging.Production.json    # Production logging settings

Kubernetes Example

Use ConfigMaps for different configuration concerns:

database-config.yaml:

apiVersion: v1
kind: ConfigMap
metadata:
  name: database-config
data:
  database.json: |
    {
      "ConnectionStrings": {
        "Default": "Server=db;Database=myapp;..."
      }
    }

logging-config.yaml:

apiVersion: v1
kind: ConfigMap
metadata:
  name: logging-config
data:
  logging.json: |
    {
      "Logging": {
        "LogLevel": {
          "Default": "Information"
        }
      }
    }

deployment.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
spec:
  template:
    spec:
      containers:
      - name: myapp
        image: myapp:latest
        volumeMounts:
        - name: database-config
          mountPath: /app/config/database.json
          subPath: database.json
        - name: logging-config
          mountPath: /app/config/logging.json
          subPath: logging.json
      volumes:
      - name: database-config
        configMap:
          name: database-config
      - name: logging-config
        configMap:
          name: logging-config

Dependency Injection

Register configuration services:

// Register settings provider
builder.Services.AddVoyagerConfiguration();

// Register custom settings provider
builder.Services.AddVoyagerConfiguration<MyCustomSettingsProvider>();

// Use in your services
public class MyService
{
    private readonly ISettingsProvider _settingsProvider;

    public MyService(ISettingsProvider settingsProvider)
    {
        _settingsProvider = settingsProvider;
    }
}

Advanced Usage

Custom Settings Provider

Implement ISettingsProvider for custom behavior:

public class MySettingsProvider : ISettingsProvider
{
    public Settings GetSettings(string filename = "appsettings")
    {
        return new Settings
        {
            FileName = filename,
            ConfigMountPath = "/custom/path",
            HostingName = "Production"
        };
    }
}

// Register in DI
builder.Services.AddVoyagerConfiguration<MySettingsProvider>();

Optional: Encrypted Configuration Files

Extension feature for encrypting sensitive configuration values:

builder.ConfigureAppConfiguration((context, config) =>
{
    var provider = context.HostingEnvironment.GetSettingsProvider();
    var encryptionKey = Environment.GetEnvironmentVariable("ENCRYPTION_KEY");

    // Regular files (plain text)
    config.AddMountConfiguration(provider, "logging");
    config.AddMountConfiguration(provider, "appsettings");

    // Encrypted files (extension feature)
    config.AddEncryptedMountConfiguration(encryptionKey, provider, "secrets");
    config.AddEncryptedMountConfiguration(encryptionKey, provider, "connectionstrings");
});

Register encryption services:

builder.Services.AddVoyagerEncryption();

Low-level API for individual encrypted files:

// Fine-grained control over encrypted files
config.AddEncryptedJsonFile("secrets.json", encryptionKey, optional: false, reloadOnChange: true);
config.AddEncryptedJsonFile("secrets.Production.json", encryptionKey, optional: true, reloadOnChange: true);

Note: Encryption is an optional extension feature. The core library is about organizing and conditionally loading configuration files.

Security Considerations

Encryption

  • Current: Uses legacy DES encryption (deprecated, for backward compatibility only)
  • Recommended: Migrate to AES-256-GCM in future versions
  • Key Management: Never hardcode encryption keys in source code
    • Use environment variables
    • Use secret management systems (Azure Key Vault, AWS Secrets Manager, etc.)
    • Use Kubernetes secrets

Best Practices

  1. Minimum Key Length: Use keys with at least 8 characters (longer for production)
  2. Secret Storage: Store encryption keys securely outside the application
  3. File Permissions: Ensure configuration files have appropriate read permissions
  4. Container Security: Mount configuration volumes as read-only (:ro)

Architecture

This library follows SOLID principles and modern .NET design patterns:

  • Single Responsibility Principle: Each class has one well-defined responsibility
  • Interface-based design: IEncryptor, ISettingsProvider, ICipherProvider, IEncryptorFactory
  • Dependency Injection: Full support for DI container registration
  • Extension methods: Organized by responsibility for better maintainability

Extension Methods Organization

The library provides extension methods organized by their specific concerns:

  • ConfigurationExtension: Non-encrypted mount configuration
  • EncryptedMountConfigurationExtensions: Encrypted mount configuration (high-level API)
  • EncryptedJsonFileExtensions: Encrypted JSON file operations (low-level API)
  • ServiceCollectionExtensions: Dependency injection registration

All extension methods are placed in the Microsoft.Extensions.DependencyInjection namespace following .NET conventions.

Note: The ConfigurationEncryptedExtension class is deprecated and will be removed in version 3.0. Use EncryptedMountConfigurationExtensions and EncryptedJsonFileExtensions instead.

Documentation

Migration Guide

For migration from version 1.x to 2.x, see Migration Guide.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Authors

See also the list of contributors who participated in this project.

Acknowledgements

  • Przemysล‚aw Wrรณbel - Icon design
  • All contributors who have helped improve this library

Support

If you encounter any issues or have suggestions:

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.1 is compatible. 
.NET Framework net48 is compatible.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.1-preview.1 55 2/10/2026
2.0.0 113 2/10/2026
2.0.0-preview.1.3 45 2/10/2026
2.0.0-preview.1.2 42 2/10/2026
1.3.0-preview.5.15 50 2/9/2026
1.3.0-preview.5 49 2/7/2026
1.3.0-preview.4 57 2/7/2026
1.3.0-preview.3 47 2/6/2026
1.3.0-preview.2 50 2/6/2026
1.3.0-preview.1 56 2/5/2026
1.2.8 1,589 9/26/2024
1.2.7 852 6/7/2024
1.2.6 199 6/6/2024
1.2.5 236 6/6/2024
1.2.4 207 6/6/2024
1.1.3 227 6/6/2024
1.1.2 569 12/1/2023
1.1.1 233 11/21/2023
1.1.0 227 11/17/2023
1.0.1 355 4/12/2023
Loading failed

v1.3.0: SRP refactoring - Extension methods split by responsibility (EncryptedMountConfigurationExtensions, EncryptedJsonFileExtensions). ConfigurationEncryptedExtension marked as obsolete. See ADR-001 for details.