Andy.Configuration
2025.7.16-rc.6
dotnet add package Andy.Configuration --version 2025.7.16-rc.6
NuGet\Install-Package Andy.Configuration -Version 2025.7.16-rc.6
<PackageReference Include="Andy.Configuration" Version="2025.7.16-rc.6" />
<PackageVersion Include="Andy.Configuration" Version="2025.7.16-rc.6" />
<PackageReference Include="Andy.Configuration" />
paket add Andy.Configuration --version 2025.7.16-rc.6
#r "nuget: Andy.Configuration, 2025.7.16-rc.6"
#:package Andy.Configuration@2025.7.16-rc.6
#addin nuget:?package=Andy.Configuration&version=2025.7.16-rc.6&prerelease
#tool nuget:?package=Andy.Configuration&version=2025.7.16-rc.6&prerelease
Andy.Configuration
A robust, type-safe configuration library for .NET applications with built-in validation, dependency injection support, and comprehensive error handling.
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
- Design Documentation - Architecture and design decisions
- API Reference - Detailed API documentation
- Configuration Guide - Configuration options and examples
- Contributing - Guidelines for contributors
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>
, andIOptionsMonitor<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:
- Open an issue on GitHub
- Check the documentation for detailed guides
Acknowledgments
Built with ❤️ using:
- .NET 8
- Microsoft.Extensions.Options
- xUnit for testing
- FluentAssertions for test assertions
- Coverlet for code coverage
Product | Versions 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. |
-
net8.0
- Microsoft.Extensions.Hosting.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 9.0.0)
- Microsoft.Extensions.Options.DataAnnotations (>= 9.0.0)
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 |