Andy.Configuration 2025.7.16-rc.6

This is a prerelease version of Andy.Configuration.
dotnet add package Andy.Configuration --version 2025.7.16-rc.6
                    
NuGet\Install-Package Andy.Configuration -Version 2025.7.16-rc.6
                    
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="Andy.Configuration" Version="2025.7.16-rc.6" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Andy.Configuration" Version="2025.7.16-rc.6" />
                    
Directory.Packages.props
<PackageReference Include="Andy.Configuration" />
                    
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 Andy.Configuration --version 2025.7.16-rc.6
                    
#r "nuget: Andy.Configuration, 2025.7.16-rc.6"
                    
#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 Andy.Configuration@2025.7.16-rc.6
                    
#: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=Andy.Configuration&version=2025.7.16-rc.6&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Andy.Configuration&version=2025.7.16-rc.6&prerelease
                    
Install as a Cake Tool

Andy.Configuration

A robust, type-safe configuration library for .NET applications with built-in validation, dependency injection support, and comprehensive error handling.

.NET License Coverage

Features

  • Type-safe configuration with strongly-typed option classes
  • Recursive validation using Data Annotations
  • Dependency injection integration with Microsoft.Extensions.DependencyInjection
  • Configuration validation on startup to catch errors early
  • Support for multiple configuration sources (JSON, environment variables, etc.)
  • Hierarchical configuration structure with nested options
  • Comprehensive test coverage (96.94% line coverage)

Installation

dotnet add package Andy.Configuration

Quick Start

1. Define Your Configuration

public class MyAppOptions
{
    [Required]
    public DatabaseOptions Database { get; set; } = new();
    
    [Required]
    public ApiOptions Api { get; set; } = new();
}

public class DatabaseOptions
{
    [Required]
    public string ConnectionString { get; set; } = string.Empty;
    
    [Range(1, 100)]
    public int MaxConnections { get; set; } = 10;
}

public class ApiOptions
{
    [Required]
    [Url]
    public string BaseUrl { get; set; } = string.Empty;
    
    [Range(1000, 300000)]
    public int TimeoutMs { get; set; } = 30000;
}

2. Configure in Startup

var builder = WebApplication.CreateBuilder(args);

// Add configuration services
builder.Services.AddAndyConfiguration(builder.Configuration);

// Enable validation on startup
builder.Services.ValidateConfigurationOnStartup();

var app = builder.Build();

3. Use in Your Application

public class MyService
{
    private readonly MyAppOptions _options;
    
    public MyService(IOptions<MyAppOptions> options)
    {
        _options = options.Value;
    }
    
    public async Task ConnectToDatabase()
    {
        // Use strongly-typed configuration
        var connectionString = _options.Database.ConnectionString;
        var maxConnections = _options.Database.MaxConnections;
        // ...
    }
}

4. Configuration File (appsettings.json)

{
  "MyApp": {
    "Database": {
      "ConnectionString": "Server=localhost;Database=myapp;",
      "MaxConnections": 20
    },
    "Api": {
      "BaseUrl": "https://api.example.com",
      "TimeoutMs": 60000
    }
  }
}

Andy CLI Configuration

This library was originally built for the Andy CLI tool and includes pre-defined configuration options:

// Use the built-in Andy configuration
builder.Services.AddAndyConfiguration(builder.Configuration);

// Access Andy options
public class MyAndyService
{
    private readonly AndyOptions _andyOptions;
    
    public MyAndyService(IOptions<AndyOptions> options)
    {
        _andyOptions = options.Value;
        
        // Access nested configuration
        var model = _andyOptions.Model.Name;
        var temperature = _andyOptions.Model.Temperature;
        var authMethod = _andyOptions.Authentication.Method;
    }
}

Documentation

Key Components

Configuration Validation

The library provides recursive validation of configuration objects:

  • Required field validation
  • Range validation for numeric values
  • Custom validation attributes
  • Nested object validation
  • Collection validation (for required collections)

Dependency Injection

Seamless integration with Microsoft.Extensions.DependencyInjection:

  • Automatic registration of options and validators
  • Support for IOptions<T>, IOptionsSnapshot<T>, and IOptionsMonitor<T>
  • Individual option section registration for granular access

Error Handling

Comprehensive error handling with detailed error messages:

  • Validation errors are collected and reported with full property paths
  • Startup validation prevents application start with invalid configuration
  • Clear error messages for troubleshooting

Testing

The library includes comprehensive unit and integration tests:

# Run tests
dotnet test

# Run with coverage
dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura

# Generate coverage report
reportgenerator -reports:"./TestResults/coverage.cobertura.xml" -targetdir:"CoverageReport" -reporttypes:Html

Contributing

We welcome contributions! Please see our Contributing Guide for details.

License

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

Support

For issues, feature requests, or questions:

Acknowledgments

Built with ❤️ using:

Product Compatible and additional computed target framework versions.
.NET 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Andy.Configuration:

Package Downloads
Andy.Llm

Andy.Llm — Large Language Model integration library for .NET.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2025.7.16-rc.6 246 7/16/2025
2025.7.16-rc.2 121 7/16/2025