Introduction
SGuard.ConfigValidation is a lightweight, production-ready tool to catch critical configuration issues before runtime. Validate your configuration files during application startup or in your CI/CD pipeline.
β¨ Why SGuard.ConfigValidation?β
Misconfigured environments, missing connection strings, or wrong URLs can cause major issues after deployment.
SGuard.ConfigValidation helps you detect these problems early, preventing runtime failures and reducing debugging time.
π Key Featuresβ
- β
Multiple Validators:
required,min_len,max_len,eq,ne,gt,gte,lt,lte,in - β JSON & YAML Support: Load configuration and app settings from JSON and YAML files
- β
JSON Schema Validation: Validate
sguard.jsonagainst JSON Schema - β Custom Validator Plugins: Extend validation capabilities with custom validators
- β CLI Tool: Command-line interface for easy validation
- β Dependency Injection: Full DI support with extension methods
- β Security Features: Built-in DoS protection, path traversal protection, and resource limits
- β Performance Optimized: Caching, streaming, and parallel validation support
- β Multiple Output Formats: Console, JSON, and text file output
- β Comprehensive Testing: High test coverage with xUnit
π§ Supported Frameworksβ
- .NET 8.0 (LTS)
- .NET 9.0
- .NET 10.0
π¦ Installationβ
Install the NuGet package:
dotnet add package SGuard.ConfigValidation
Or via Package Manager Console:
Install-Package SGuard.ConfigValidation
π Quick Startβ
1. Create Configuration File (sguard.json)β
{
"version": "1",
"environments": [
{
"id": "prod",
"name": "Production",
"path": "appsettings.Production.json"
}
],
"rules": [
{
"id": "connection-string-rule",
"environments": ["prod"],
"rule": {
"id": "required-connection-string",
"conditions": [
{
"key": "ConnectionStrings:DefaultConnection",
"condition": [
{
"validator": "required",
"message": "Connection string is required"
}
]
}
]
}
}
]
}
2. Register Servicesβ
using Microsoft.Extensions.DependencyInjection;
using SGuard.ConfigValidation.Extensions;
var services = new ServiceCollection();
services.AddSGuardConfigValidation();
var serviceProvider = services.BuildServiceProvider();
3. Validate Configurationβ
using SGuard.ConfigValidation.Services.Abstract;
var ruleEngine = serviceProvider.GetRequiredService<IRuleEngine>();
var result = await ruleEngine.ValidateEnvironmentAsync("sguard.json", "prod");
if (!result.IsValid)
{
Console.WriteLine("Validation failed!");
foreach (var error in result.Errors)
{
Console.WriteLine($"- {error}");
}
}
π Next Stepsβ
- Getting Started - Detailed installation and setup guide
- API Reference - Complete API documentation
- Examples - Real-world scenarios and code samples
π€ Contributingβ
Contributions are welcome! Please visit our GitHub repository to:
- Report issues
- Submit pull requests
- Join discussions
π Licenseβ
This project is licensed under the MIT License - see the LICENSE file for details.