Bundle: redb-route / redb.Route.Validation.Adapters (redb.Route.Validation.Adapters.txt), 5 files Snapshot: 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 Index: https://redbase.app/src/dev-2026-12-06/redb-route/_index.txt ==== Path: redb-route/redb.Route.Validation.Adapters/DataAnnotationsValidator.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/DataAnnotationsValidator.cs ---- using System.ComponentModel.DataAnnotations; using redb.Route.Abstractions; namespace redb.Route.Validation.Adapters; /// /// Bridges System.ComponentModel.DataAnnotations to redb.Route's . /// Runs /// against the exchange body and aggregates errors with their member names. /// public sealed class DataAnnotationsValidator : IMessageValidator { private readonly ValidationSeverity _severity; private readonly IServiceProvider? _serviceProvider; /// /// Creates a DataAnnotations-backed message validator. /// /// Severity for failures (default ). /// /// Optional propagated to /// for IValidatableObject implementations that need DI services. /// public DataAnnotationsValidator( ValidationSeverity severity = ValidationSeverity.Error, IServiceProvider? serviceProvider = null) { _severity = severity; _serviceProvider = serviceProvider; } /// public ValidationResult Validate(IExchange exchange) { ArgumentNullException.ThrowIfNull(exchange); var body = exchange.In.Body; if (body is null) return ValidationResult.Failure(new[] { "Message body is null." }, _severity); var ctx = new ValidationContext(body, _serviceProvider, items: null); var results = new List(); var ok = Validator.TryValidateObject(body, ctx, results, validateAllProperties: true); if (ok) return ValidationResult.Success(); var errors = results .Select(r => r.MemberNames.Any() ? $"{string.Join(",", r.MemberNames)}: {r.ErrorMessage}" : (r.ErrorMessage ?? "Validation failed")) .ToArray(); return ValidationResult.Failure(errors, _severity); } } Path: redb-route/redb.Route.Validation.Adapters/FluentValidationMessageValidator.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/FluentValidationMessageValidator.cs ---- using FluentValidation; using redb.Route.Abstractions; namespace redb.Route.Validation.Adapters; /// /// Bridges FluentValidation's /// to redb.Route's . /// /// The exchange body is cast to before validation. A null body or /// a body of incompatible type yields a single error result; the supplied severity governs /// how reacts. /// /// /// The expected body type. public sealed class FluentValidationMessageValidator : IMessageValidator { private readonly IValidator _validator; private readonly ValidationSeverity _severity; /// /// Creates a FluentValidation-backed message validator. /// /// FluentValidation validator instance. /// Severity for failures (default ). public FluentValidationMessageValidator(IValidator validator, ValidationSeverity severity = ValidationSeverity.Error) { _validator = validator ?? throw new ArgumentNullException(nameof(validator)); _severity = severity; } /// public ValidationResult Validate(IExchange exchange) { ArgumentNullException.ThrowIfNull(exchange); var body = exchange.In.Body; if (body is null) return ValidationResult.Failure(new[] { "Message body is null." }, _severity); if (body is not T typed) return ValidationResult.Failure( new[] { $"Body of type '{body.GetType().FullName}' is not assignable to '{typeof(T).FullName}'." }, _severity); var result = _validator.Validate(typed); if (result.IsValid) return ValidationResult.Success(); var errors = result.Errors .Select(e => string.IsNullOrEmpty(e.PropertyName) ? e.ErrorMessage : $"{e.PropertyName}: {e.ErrorMessage}") .ToArray(); return ValidationResult.Failure(errors, _severity); } } Path: redb-route/redb.Route.Validation.Adapters/README.md 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/README.md ---- # redb.Route.Validation.Adapters Validation adapters for [redb.Route](../README.md): bridges **FluentValidation** and **System.ComponentModel.DataAnnotations** to the `IMessageValidator` contract used in route pipelines. [![NuGet](https://img.shields.io/nuget/v/redb.Route.Validation.Adapters?label=NuGet&color=blue)](https://www.nuget.org/packages/redb.Route.Validation.Adapters) [![License: Apache 2.0](https://img.shields.io/badge/license-Apache%202.0-blue)](../../LICENSE) ## Installation ```bash dotnet add package redb.Route.Validation.Adapters ``` ## Usage ### FluentValidation ```csharp using FluentValidation; using redb.Route.Validation.Adapters; public class OrderValidator : AbstractValidator { public OrderValidator() { RuleFor(o => o.Id).NotEmpty(); RuleFor(o => o.Amount).GreaterThan(0); } } // Via DSL extension From("kafka://orders?brokers=localhost:9092") .ValidateFluent(new OrderValidator()) .To("direct://process"); // Or directly From("kafka://orders?brokers=localhost:9092") .Validate(new FluentValidationMessageValidator(new OrderValidator())) .To("direct://process"); ``` ### DataAnnotations ```csharp using System.ComponentModel.DataAnnotations; using redb.Route.Validation.Adapters; public class Order { [Required] public string Id { get; set; } = string.Empty; [Range(0.01, double.MaxValue)] public decimal Amount { get; set; } } // Via DSL extension From("direct://input") .ValidateAnnotations() .To("direct://process"); // With optional DI service provider for IValidatableObject From("direct://input") .ValidateAnnotations(serviceProvider: sp) .To("direct://process"); ``` ### Severity and error handling Both adapters accept a `ValidationSeverity` and a `throwOnFailure` flag: ```csharp // Soft warning — pipeline continues, no exception thrown From("direct://input") .ValidateFluent(new OrderValidator(), ValidationSeverity.Warning) .To("direct://process"); // Hard error, but suppress exception (inspect exchange.ValidationErrors manually) From("direct://input") .ValidateAnnotations(throwOnFailure: false) .To("direct://process"); ``` ## Key Classes | Class / Method | Description | |---|---| | `FluentValidationMessageValidator` | `IMessageValidator` backed by a FluentValidation `IValidator` | | `DataAnnotationsValidator` | `IMessageValidator` backed by `System.ComponentModel.DataAnnotations` | | `ValidationDslExtensions.ValidateFluent` | DSL shortcut to attach FluentValidation to a route | | `ValidationDslExtensions.ValidateAnnotations` | DSL shortcut to attach DataAnnotations validation to a route | ## Part of [redb.Route](../README.md) — ESB & EIP Framework for .NET 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); } } Path: redb-route/redb.Route.Validation.Adapters/redb.Route.Validation.Adapters.csproj 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/redb.Route.Validation.Adapters.csproj ---- redb.Route.Validation.Adapters Validation adapters for redb.Route: FluentValidation and DataAnnotations integrations exposed as IMessageValidator implementations. esb;routing;validation;fluentvalidation;dataannotations