ConfigurationValidation.AspNetCore
1.0.0
See the version list below for details.
dotnet add package ConfigurationValidation.AspNetCore --version 1.0.0
NuGet\Install-Package ConfigurationValidation.AspNetCore -Version 1.0.0
<PackageReference Include="ConfigurationValidation.AspNetCore" Version="1.0.0" />
paket add ConfigurationValidation.AspNetCore --version 1.0.0
#r "nuget: ConfigurationValidation.AspNetCore, 1.0.0"
// Install ConfigurationValidation.AspNetCore as a Cake Addin #addin nuget:?package=ConfigurationValidation.AspNetCore&version=1.0.0 // Install ConfigurationValidation.AspNetCore as a Cake Tool #tool nuget:?package=ConfigurationValidation.AspNetCore&version=1.0.0
ConfigurationValidation.AspNetCore
Incorporates usage of ConfigurationValidation within Asp.Net (Core) applications.
Provides three ways of handling invalid configurations:
- Request filter preventing application startup on invalid configuration
- Root page (yellow page of error) displaying incorrect configuration values
- Health check for configuration
Also provides extension shorcuts for configuration validation usage in Asp.Net application for easy functionality registrations.
Member of Salix.AspNetCore.Utilities packages
See also other packages for some other/related functionality in Asp.Net Core (mostly APIs):
- JSON Error handler
- API dynamic FrontPage (with binaries versioning approaches)
- Health check with JSON result + Health page
ConfigurationValidation
Main functionality, which is wrapped here has its own repository (Click HERE) explaining Configuration validation approach. It has documentation describing how to create validatable configuration objects in application(s).
ASP.NET Integration
All usage is set up in program.cs
file.
See also repository Sample project on real implementation.
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
// <----- Register validatable configuration(s) you define in your app (see ConfigurationValidation package on how to create these).
builder.Services.ConfigureValidatableSetting<SampleLogicConfig>(builder.Configuration.GetSection("LogicConfiguration"));
// <----- Enabling this will prevent app startup when config is wrong (should see startup logging for troubleshooting)
// builder.Services.AddConfigurationValidation();
// <----- Add Health check for configuration (also enable app.UseHeathChecks() below)
// builder.Services.AddConfigurationHealthCheck(builder.Environment.IsDevelopment());
builder.Services.AddControllers();
var app = builder.Build();
app.UseHttpsRedirection();
// <----- Displays yellow screen of error when config is wrong (only for root URL ("/")
app.UseConfigurationValidationErrorPage();
// <----- Enable together with builder.Services.AddConfgurationHealthCheck() above.
// app.UseHealthChecks("/health");
app.UseAuthorization();
app.MapControllers();
app.Run();
}
}
Code above displays all three approaches (two of them commented out).
Configuration object registration
Package has extension methods to register defined validatable configuration objects with dependency injection container.
They register both object itself and IOptions<> instances with container.
// Program.cs
var builder = WebApplication.CreateBuilder(args);
builder.Services.ConfigureValidatableSetting<MyConfigClass>(builder.Configuration.GetSection("MyConfigSection"));
// Register non-validatable configuration settings class
builder.Services.ConfigureSetting<MyConfigClass>(builder.Configuration.GetSection("MyConfigSection"))
Prevent startup (Filter)
// Program.cs
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddConfigurationValidation();
Yellow error page
Is shown when root page is invoked (https://myaspnetapp.com/) when configuration is invalidated. If configuration is correct - displays normal root page (if one exists). Does not show page or impact any sub-routes work (if they still work with incorrect configuration).
// Program.cs
var builder = WebApplication.CreateBuilder(args);
// ...
var app = builder.Build();
app.UseConfigurationValidationErrorPage();
// ...
Health check
Adds health check for validatable configuration objects.
NOTE: Someone should invoke health check to actually see configuration is broken (or use monitoring tools to get notified on that).
// Program.cs
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddConfigurationHealthCheck(builder.Environment.IsDevelopment());
// ...
var app = builder.Build();
app.UseHealthChecks("/health");
// ...
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
-
net7.0
- ConfigurationValidation (>= 1.1.1)
- Microsoft.AspNetCore.Diagnostics.HealthChecks (>= 2.2.0)
- Microsoft.AspNetCore.Hosting.Abstractions (>= 2.2.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 7.0.0)
- Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions (>= 7.0.1)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 7.0.0)
- Microsoft.Net.Http.Headers (>= 2.2.8)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Initial: Moved from aspNetCore.Utilities meta-package.