Skip to main content

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.json against 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​

🀝 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.