🔧 A lightweight, source-generated configuration binder for .NET — just tag your class with
[ConfigSection]and go.
- ✅ Compile-time generation of config binding and registration code
- ✅ Supports both
IOptions<T>andAddSingleton<T>modes - ✅ Full support for System.ComponentModel.Annotations
- ✅ No reflection at runtime
- ✅ Drop-in integration with
appsettings.json - ✅ Currently only supports {get; set;} and {get; init;}.
🛠 Binding Modes
| Mode | Behavior |
|---|---|
Singleton |
Registers the instance via AddSingleton<T> |
IOptions |
Uses services.Configure<T>() |
Both |
Adds both for flexibility |
dotnet add package Routya.ConfigKit.GeneratorConfigSection("MyService", ConfigBindingMode.IOptions)
The 'MyService' in ConfigSection is the section name within your configuration (eg. appsettings.json, Azure App Configuration)
{
"MyService": {
"RetryCount": 3,
"UseCaching": false
}
}ConfigBindingMode.IOptions
using System.ComponentModel.DataAnnotations;
using Routya.ConfigKit;
[ConfigSection("MyService", mode: ConfigBindingMode.IOptions)]
public partial class MyServiceOptions
{
[Required]
public int RetryCount { get; init; }
public bool UseCaching { get; init; } = true;
}Generates
public static IServiceCollection AddMyServiceOptions(this IServiceCollection services, IConfiguration configuration)
{
services.AddOptions<MyServiceOptions>()
.Bind(configuration.GetSection("MyService"))
.ValidateDataAnnotations()
.ValidateOnStart();
return services;
}ConfigBindingMode.Singleton
using System.ComponentModel.DataAnnotations;
using Routya.ConfigKit;
[ConfigSection("MyService", ConfigBindingMode.Singleton)]
public partial class MyServiceOptions
{
[Required]
public int RetryCount { get; init; }
public bool UseCaching { get; init; } = true;
}Generates
public static IServiceCollection AddMyServiceOptions(this IServiceCollection services, IConfiguration configuration)
{
var options = new MyServiceOptions()
{
RetryCount = configuration.GetValue<int>("MyService:RetryCount"),
UseCaching = configuration.GetValue<bool>("MyService:UseCaching"),
};
var validationContext = new ValidationContext(options);
Validator.ValidateObject(options, validationContext, validateAllProperties: true);
services.AddSingleton(options);
return services;
}builder.Services.AddMyServiceOptions(builder.Configuration);- Add support for complex/nested config objects
- {get; private set;}
🧰 Routya
A high-performance, minimal-overhead CQRS + MediatR alternative for .NET applications. Supports request/notification dispatching, behavior pipelines, scoped resolution, and performance-optimized dispatchers.
A companion library for consistent API response modeling. Wraps results with success/failure metadata, integrates with ProblemDetails, and streamlines controller return types.