Voyager.Configuration.MountPath 2.0.0

There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Voyager.Configuration.MountPath --version 2.0.0
                    
NuGet\Install-Package Voyager.Configuration.MountPath -Version 2.0.0
                    
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="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Voyager.Configuration.MountPath" Version="2.0.0" />
                    
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 2.0.0
                    
#r "nuget: Voyager.Configuration.MountPath, 2.0.0"
                    
#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@2.0.0
                    
#: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=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Voyager.Configuration.MountPath&version=2.0.0
                    
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

โš ๏ธ DEPRECATION NOTICE: Built-in Encryption The built-in encryption feature is deprecated and will be removed in version 3.0. We recommend migrating to external secret management tools like Mozilla SOPS, Kubernetes Secrets, or cloud providers (Azure Key Vault, AWS Secrets Manager). See ADR-003: Encryption Delegation for migration guidance and rationale.

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
  • ๐Ÿ”Œ 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>();

โš ๏ธ DEPRECATED: Encrypted Configuration Files

This feature is deprecated and will be removed in version 3.0. Please migrate to external secret management tools.

Built-in encryption (deprecated):

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");

    // โš ๏ธ DEPRECATED - Use SOPS instead
    config.AddEncryptedMountConfiguration(encryptionKey, provider, "secrets");
    config.AddEncryptedMountConfiguration(encryptionKey, provider, "connectionstrings");
});

Recommended alternative: Mozilla SOPS

Encrypt configuration files using SOPS before loading:

# Encrypt files with SOPS (one-time setup)
sops -e config/secrets.json > config/secrets.json

# Decrypt in your deployment script or init container
sops -d /config-encrypted/secrets.json > /config/secrets.json
// Load decrypted files normally - no code changes needed!
builder.ConfigureAppConfiguration((context, config) =>
{
    var provider = context.HostingEnvironment.GetSettingsProvider();

    config.AddMountConfiguration(provider, "logging");
    config.AddMountConfiguration(provider, "secrets");     // Already decrypted by SOPS
    config.AddMountConfiguration(provider, "appsettings");
});

Why migrate to SOPS?

  • โœ… More secure: AES-256-GCM instead of legacy DES
  • โœ… GitOps-friendly: Encrypted files can be committed to Git
  • โœ… Key management: Integrates with AWS KMS, Azure Key Vault, GCP KMS, Age
  • โœ… No code changes: Decrypt before loading, library code stays the same
  • โœ… Better tooling: Edit encrypted files without manual decrypt/encrypt cycle

See ADR-003: Encryption Delegation to External Tools for:

  • Detailed SOPS setup guide
  • Migration examples for Kubernetes and Supervisor
  • Comparison of secret management solutions
  • Step-by-step migration path

Security Considerations

โš ๏ธ Encryption Feature Deprecated

Built-in encryption is deprecated and will be removed in version 3.0.

  • Current implementation: Legacy DES encryption (56-bit, insecure)
  • Status: Deprecated for backward compatibility only
  • Recommendation: Migrate to external secret management tools

Instead of built-in encryption, use industry-standard tools:

  1. Mozilla SOPS - File encryption for GitOps workflows

    • Encrypts JSON/YAML values while keeping structure readable
    • Supports AWS KMS, Azure Key Vault, GCP KMS, Age
    • Git-friendly diffs
    • Best for: GitOps, encrypted configs in Git
  2. Kubernetes Secrets + Sealed Secrets

    • Native Kubernetes secret management
    • Sealed Secrets for GitOps-safe encrypted secrets
    • Best for: Kubernetes deployments
  3. Cloud Secret Managers

    • Azure Key Vault, AWS Secrets Manager, GCP Secret Manager
    • Enterprise-grade key rotation and audit logging
    • Best for: Cloud-native applications
  4. dotnet user-secrets

    • For development environments only
    • Best for: Local development

See ADR-003 for detailed migration guide.

Best Practices

  1. External Secret Management: Use SOPS, Kubernetes Secrets, or cloud providers
  2. File Permissions: Ensure configuration files have appropriate read permissions
  3. Container Security: Mount configuration volumes as read-only (:ro)
  4. Key Management: Never hardcode secrets in source code or images
  5. Separation of Concerns: Configuration loading โ‰  secret management

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 34 2/10/2026
2.0.0 84 2/10/2026
2.0.0-preview.1.3 30 2/10/2026
2.0.0-preview.1.2 28 2/10/2026
1.3.0-preview.5.15 40 2/9/2026
1.3.0-preview.5 40 2/7/2026
1.3.0-preview.4 49 2/7/2026
1.3.0-preview.3 40 2/6/2026
1.3.0-preview.2 43 2/6/2026
1.3.0-preview.1 49 2/5/2026
1.2.8 1,571 9/26/2024
1.2.7 838 6/7/2024
1.2.6 186 6/6/2024
1.2.5 223 6/6/2024
1.2.4 191 6/6/2024
1.1.3 214 6/6/2024
1.1.2 557 12/1/2023
1.1.1 223 11/21/2023
1.1.0 217 11/17/2023
1.0.1 345 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.