Path: redb-route/redb.Route.Validation.Adapters/ValidationDslExtensions.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route.Validation.Adapters/ValidationDslExtensions.cs
----
using FluentValidation;
using redb.Route.Abstractions;
using redb.Route.Definitions;
using redb.Route.Validation;
namespace redb.Route.Validation.Adapters;
///
/// Fluent DSL helpers for attaching the
/// and adapters to a route definition.
///
public static class ValidationDslExtensions
{
///
/// Attaches a FluentValidation validator as an inline pipeline step.
///
/// Expected body type.
/// Route definition.
/// FluentValidation validator.
/// Severity for failures (default ).
///
/// When severity is , controls whether a
/// is thrown. Ignored for warnings (never throws).
///
public static IRouteDefinition ValidateFluent(
this IRouteDefinition route,
IValidator validator,
ValidationSeverity severity = ValidationSeverity.Error,
bool throwOnFailure = true)
{
ArgumentNullException.ThrowIfNull(route);
ArgumentNullException.ThrowIfNull(validator);
return route.Validate(new FluentValidationMessageValidator(validator, severity), throwOnFailure);
}
///
/// Attaches a DataAnnotations validator as an inline pipeline step.
///
/// Route definition.
/// Severity for failures (default ).
///
/// When severity is , controls whether a
/// is thrown. Ignored for warnings (never throws).
///
///
/// Optional service provider passed to .
///
public static IRouteDefinition ValidateAnnotations(
this IRouteDefinition route,
ValidationSeverity severity = ValidationSeverity.Error,
bool throwOnFailure = true,
IServiceProvider? serviceProvider = null)
{
ArgumentNullException.ThrowIfNull(route);
return route.Validate(new DataAnnotationsValidator(severity, serviceProvider), throwOnFailure);
}
}