NuGet · nuget

Redeon.SuperSiteEngineCore.Web.Eltheon.Core.Features.Validation

Core Feature Validation for Eltheon Framework

Install

Install-Kommandos

dotnet add package Redeon.SuperSiteEngineCore.Web.Eltheon.Core.Features.Validation --version 0.9.0.4
<PackageReference Include="Redeon.SuperSiteEngineCore.Web.Eltheon.Core.Features.Validation" Version="0.9.0.4" />
paket add Redeon.SuperSiteEngineCore.Web.Eltheon.Core.Features.Validation --version 0.9.0.4
Install-Package Redeon.SuperSiteEngineCore.Web.Eltheon.Core.Features.Validation -Version 0.9.0.4

README

Vorschau

Redeon.SuperSiteEngineCore.Web.Eltheon.Core.Features.Validation

Server-side validation and error-handling feature for Eltheon. Ships structured error DTOs, factories, DataAnnotations validation (including nested objects), sync/async validator base classes, and Minimal API endpoint filters that return either ProblemDetails or a consistent ErrorResponse payload. A Swagger operation filter adds application/problem+json content types.

What you get

  • DTOs: ValidationError, ErrorResponse<TError>, ValidationErrorResponse, base ErrorBase, contract IErrorDetail.
  • Validation helpers: recursive DataAnnotationValidator, SyncValidatorBase<T> / AsyncValidatorBase<T>, interfaces IValidator<T>, ISyncValidator<T>, IAsyncValidator<T>.
  • Minimal API integration: ValidationFilter<T> via .Validate<T>() plus AddEndpointValidation() DI helper.
  • MVC integration: ValidationActionFilter (global ModelState → structured error/ProblemDetails) via .AddGlobalValidationFilter() on IMvcBuilder.
  • Swagger: ProblemDetailsContentTypeOperationFilter to mirror application/json as application/problem+json.

Usage (Minimal API)

builder.Services.AddEndpointValidation(); // enable opt-in filters

var app = builder.Build();

app.MapPost("/api/things", (ThingDto dto) =>
{
    // Only runs when validation passed
    return Results.Ok(new { success = true });
}).Validate<ThingDto>(); // DataAnnotations + custom validators

Requests are validated in this order:

  1. DataAnnotations (including nested objects/collections and IValidatableObject)
  2. All registered IValidator<T> implementations

If errors exist:

  • If Accept: application/problem+json or X-Use-ProblemDetails: true, a ProblemDetails payload is returned.
  • Otherwise: 400 BadRequest with ErrorResponse<IErrorDetail> { Errors = [...] }.

Custom validator

public sealed class ThingValidator : ISyncValidator<ThingDto>
{
    public bool TryValidate(ThingDto input, List<IErrorDetail> errors)
    {
        if (string.IsNullOrWhiteSpace(input.Name))
            errors.Add(ValidationErrorFactory.Create("NAME_REQUIRED", "Name is required", nameof(input.Name)));
        return errors.Count == 0;
    }
}

Register via DI:

builder.Services.AddScoped<IValidator<ThingDto>, ThingValidator>();

Global MVC validation

builder.Services
    .AddRazorPages()
    .AddGlobalValidationFilter(); // adds ValidationActionFilter to MVC

This converts ModelState errors across controllers/Razor pages into ErrorResponse (or ProblemDetails if the client requests it).

Swagger setup

services.AddSwaggerGen(o =>
{
    o.OperationFilter<ProblemDetailsContentTypeOperationFilter>();
});

Notes

  • Target framework: net9.0
  • Package reference: Swashbuckle.AspNetCore.SwaggerGen for the operation filter.
  • Feature is versioned independently; bump the csproj Version when you change its public surface.