ConfigurationOptionsValidator 1.0.7
dotnet add package ConfigurationOptionsValidator --version 1.0.7
NuGet\Install-Package ConfigurationOptionsValidator -Version 1.0.7
<PackageReference Include="ConfigurationOptionsValidator" Version="1.0.7" />
<PackageVersion Include="ConfigurationOptionsValidator" Version="1.0.7" />
<PackageReference Include="ConfigurationOptionsValidator" />
paket add ConfigurationOptionsValidator --version 1.0.7
#r "nuget: ConfigurationOptionsValidator, 1.0.7"
#:package ConfigurationOptionsValidator@1.0.7
#addin nuget:?package=ConfigurationOptionsValidator&version=1.0.7
#tool nuget:?package=ConfigurationOptionsValidator&version=1.0.7
ConfigurationOptionsValidator
Version 1.0.7
ConfigurationOptionsValidator is a lightweight, powerful, and fully automated configuration validation library for .NET applications.
It ensures that every configuration class in your application is:
✔ Registered
✔ Validated
✔ Checked for missing or invalid values
✔ Logged safely through Serilog
✔ Handled correctly depending on workload (Blazor, API, Console)
ConfigurationOptionsValidator works seamlessly with the Options Pattern, which is a recommended approach for managing configuration in .NET. The Options pattern removes magic strings from your code, making it more readable and flexible. While it’s a great practice to use, even if you’re not using the Options pattern, this library can still help by validating your appsettings values and checking for any missing or incorrect properties.
This library prevents your applications from starting with invalid appsettings.json data, improving reliability, security, and developer experience.
🧩 Framework Support
ConfigurationOptionsValidator supports the following .NET versions via multi-targeting:
- ✅ .NET 8 (LTS)
- ✅ .NET 9
- ✅ .NET 10 (LTS)
The package automatically selects the most appropriate target framework at build time, ensuring maximum compatibility without requiring any changes from consumers.
🚀 What’s New in v1.0.7
- ✅ Full automation across Blazor, API, and Console workloads
- ✅ Multi-targeting support for .NET 8, .NET 9, and .NET 10
- ✅ Improved startup validation consistency across application types Version 1.0.7 introduces full automation across all workloads:
✅ Blazor
builder.AddConfigurationValidation();
app.ValidateBlazorConfigurationOnStartup();
✅ API
builder.AddConfigurationValidation();
builder.ValidateApiConfigurationOnStartup();
✅ Console Applications
builder.AddConfigurationValidation();
host.ValidateConsoleConfigurationOnStartup();
✅ Mandatory Requirement
Every configuration class must implement IValidatedOptions Any class you want automatically validated must implement the marker interface#:
public class SMTPOptions : IValidatedOptions
{
public string Host { get; set; }
public int Port { get; set; }
}
Installation
Install the package via NuGet:
dotnet add package ConfigurationOptionsValidator --version 1.0.6
Setup
1. Blazor
In your Program.cs:
var builder = WebApplication.CreateBuilder(args);
// Register validators + discover option types
builder.AddConfigurationValidation();
var app = builder.Build();
// Run validation + show HTML error page if needed
app.ValidateBlazorConfigurationOnStartup();
app.Run();
If a configuration is missing, the user is safely redirected to:
/config-error
The page is automatically generated with your Serilog settings.
2. Web API
In your Program.cs:
var builder = WebApplication.CreateBuilder(args);
// Auto-register validators and discover config types
builder.AddConfigurationValidation();
// Validate API configuration (fail-fast)
builder.ValidateApiConfigurationOnStartup();
var app = builder.Build();
2. Console Application
In your Program.cs:
internal class Program
{
private static async Task Main(string[] args)
{
// Create builder (loads config automatically)
var builder = Host.CreateApplicationBuilder(args);
// Auto-register validators + options
builder.AddConfigurationValidation();
// Build host
var host = builder.Build();
// Validate before running the app
host.ValidateConsoleConfigurationOnStartup();
// Run console app logic
var app = ActivatorUtilities.CreateInstance<ApplicationService>(host.Services);
await app.RunAsync();
}
}
Error Page Security for Web Apps
For enhanced security, configure error handling to restrict access to error pages in production environments. You can add the following settings to your appsettings.json to prevent exposing errors to end users:
"ConfigurationErrorPageSettings": {
"ForbiddenMessage": "Access denied. This page is only visible on the server.",
"SupportContact": {
"Email": "support@company.com",
"Phone": "+44 7890 123456",
"Website": "https://support.company.com"
}
}
This prevents leaking sensitive configuration details to the public.
Serilog Logging
If logPath is not set, logs are written to:
In your C:\TaskLogs:
You can override the path by setting:
builder.ValidateApiConfigurationOnStartup(logPath: "C:/mylogs");
This prevents leaking sensitive configuration details to the public.
Why Use ConfigurationOptionsValidator?
✔ No more guessing which config values are missing ✔ No more runtime crashes due to bad settings ✔ Works with Blazor, API, Console (automatically) ✔ Instant validation on startup ✔ Secure error handling ✔ Cleaner, more maintainable configuration code
License
This project is licensed under the MIT License. See the LICENSE file for details.
| 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 is compatible. 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 is compatible. 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. |
-
net10.0
- Serilog (>= 4.3.0)
- Serilog.Sinks.File (>= 7.0.0)
-
net8.0
- Serilog (>= 4.3.0)
- Serilog.Sinks.File (>= 7.0.0)
-
net9.0
- Serilog (>= 4.3.0)
- Serilog.Sinks.File (>= 7.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.