RA.Utilities.Application.Validation 10.2.0

Prefix Reserved
dotnet add package RA.Utilities.Application.Validation --version 10.2.0
                    
NuGet\Install-Package RA.Utilities.Application.Validation -Version 10.2.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RA.Utilities.Application.Validation" Version="10.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RA.Utilities.Application.Validation" Version="10.2.0" />
                    
Directory.Packages.props
<PackageReference Include="RA.Utilities.Application.Validation" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add RA.Utilities.Application.Validation --version 10.2.0
                    
#r "nuget: RA.Utilities.Application.Validation, 10.2.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package RA.Utilities.Application.Validation@10.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=RA.Utilities.Application.Validation&version=10.2.0
                    
Install as a Cake Addin
#tool nuget:?package=RA.Utilities.Application.Validation&version=10.2.0
                    
Install as a Cake Tool

RA.Utilities.Application.Validation

NuGet version Codecov GitHub license NuGet Downloads Documentation

RA.Utilities.Application.Validation provides reusable validators and helpers built on FluentValidation for validating incoming requests.

Run every registered validator for a request in parallel, aggregate the failures, and convert them into a standardized BadRequestException — the payload that RA.Utilities.Api middleware translates into a consistent HTTP 400 response — without writing the orchestration code yourself.

✨ Key Features

  • Parallel validation orchestration: ValidationUtilities.ValidateAsync executes all validators for a request concurrently — each with its own ValidationContext, so results cannot leak between validators — and flattens the failures into a single array, forwarding your CancellationToken to every validator.
  • Standardized error payloads: ValidationUtilities.CreateValidationErrorResult maps FluentValidation's ValidationFailure[] into a BadRequestException carrying structured ValidationError entries (PropertyName, AttemptedValue, ErrorCode).
  • Value-object-backed rules: MustBeValidCurrency(), MustBeValidEmail(), MustBeValidSsn(), and MustBeValidIban() validate string? properties through the value objects of RA.Utilities.Core.ValueObjects, so request validation and the domain share one set of rules.
  • ISO 4217 format rule: MustMatchesCurrencyFormat() checks the currency shape (3 uppercase letters) with a source-generated compiled regex.

Installation

You can install the package via the .NET CLI:

dotnet add package RA.Utilities.Application.Validation
Install-Package RA.Utilities.Application.Validation

Usage

Run all validators for a request

using FluentValidation;
using FluentValidation.Results;
using RA.Utilities.Application.Validation.Extensions;
using RA.Utilities.Application.Validation.Utilities;

public record CreateOrderRequest(string Currency, decimal Amount);

public class CreateOrderValidator : AbstractValidator<CreateOrderRequest>
{
    public CreateOrderValidator()
    {
        RuleFor(x => x.Currency).MustMatchesCurrencyFormat();
        RuleFor(x => x.Amount).GreaterThan(0);
    }
}

Run the validators and throw the standardized exception on failure:

ValidationFailure[] failures = await ValidationUtilities.ValidateAsync(
    request, [new CreateOrderValidator()], CancellationToken.None);

if (failures.Length > 0)
{
    throw ValidationUtilities.CreateValidationErrorResult(failures);
}

The utilities are static — no configuration of their own is required; validators are supplied by your own DI container.

Value-object-backed validation rules

The MustBeValid* rules in RA.Utilities.Application.Validation.Extensions construct the matching value object (Currency, Email, SSN, IBAN) behind the scenes. Any input the value object rejects fails the rule for that property path:

using RA.Utilities.Application.Validation.Extensions;

public record RegisterUserRequest(string Email, string Currency, string Ssn, string Iban);

public class RegisterUserValidator : AbstractValidator<RegisterUserRequest>
{
    public RegisterUserValidator()
    {
        RuleFor(x => x.Email).MustBeValidEmail();
        RuleFor(x => x.Currency).MustBeValidCurrency();
        RuleFor(x => x.Ssn).MustBeValidSsn();
        RuleFor(x => x.Iban).MustBeValidIban();
    }
}

MustBeValidIban() normalizes casing and grouping separators and checks the 13–34 character structure plus the ISO 7064 mod-97 checksum. It does not validate per-country lengths or registry membership — do that separately when your domain requires it.

Because the value object constructors reject null, empty and whitespace input, these rules also fail on missing values — unlike MustMatchesCurrencyFormat(), where null passes and requiredness is left to NotNull() / NotEmpty(). Use .When(x => !string.IsNullOrWhiteSpace(...)) when a field is genuinely optional.

The failure message is the generic BadRequestException message ("The request is invalid."), not the value object's specific message; chain WithMessage(...) if you want a property-specific message.

Dependencies

  • FluentValidation (12.1.1)
  • RA.Utilities.Core.Exceptions
  • RA.Utilities.Core.ValueObjects (10.2.0 or later) — provides Currency, Email, SSN, and IBAN for the MustBeValid* rules

Additional documentation

For more information on how this package fits into the larger RA.Utilities ecosystem, please see the main repository documentation.

Contributing

Contributions are welcome! If you have a suggestion or find a bug, please open an issue to discuss it. Please follow the contribution guidelines outlined in the other projects in this repository.

Product Compatible and additional computed target framework versions.
.NET 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on RA.Utilities.Application.Validation:

Package Downloads
RA.Utilities.Feature

Provides a base implementation for the feature slice/vertical slice architecture pattern, including base handlers, validation behaviors, and exception handling for CQRS.

RA.Utilities.Dispatcher

Provides a lightweight, source-generated mediator (dispatcher) for CQRS, including Result-based request and notification dispatch, pipeline behaviors, validation, and automatic handler registration.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
10.2.0 159 10/18/2026
10.0.1 125 9/28/2026
10.0.0 194 1/12/2026