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
<PackageReference Include="RA.Utilities.Application.Validation" Version="10.2.0" />
<PackageVersion Include="RA.Utilities.Application.Validation" Version="10.2.0" />
<PackageReference Include="RA.Utilities.Application.Validation" />
paket add RA.Utilities.Application.Validation --version 10.2.0
#r "nuget: RA.Utilities.Application.Validation, 10.2.0"
#:package RA.Utilities.Application.Validation@10.2.0
#addin nuget:?package=RA.Utilities.Application.Validation&version=10.2.0
#tool nuget:?package=RA.Utilities.Application.Validation&version=10.2.0
RA.Utilities.Application.Validation
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.ValidateAsyncexecutes all validators for a request concurrently — each with its ownValidationContext, so results cannot leak between validators — and flattens the failures into a single array, forwarding yourCancellationTokento every validator. - Standardized error payloads:
ValidationUtilities.CreateValidationErrorResultmaps FluentValidation'sValidationFailure[]into aBadRequestExceptioncarrying structuredValidationErrorentries (PropertyName,AttemptedValue,ErrorCode). - Value-object-backed rules:
MustBeValidCurrency(),MustBeValidEmail(),MustBeValidSsn(), andMustBeValidIban()validatestring?properties through the value objects ofRA.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.ExceptionsRA.Utilities.Core.ValueObjects(10.2.0 or later) — providesCurrency,Email,SSN, andIBANfor theMustBeValid*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 | Versions 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. |
-
net10.0
- FluentValidation (>= 12.1.1)
- RA.Utilities.Core.Exceptions (>= 10.1.0)
- RA.Utilities.Core.ValueObjects (>= 10.2.0)
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.