Tolitech.Application.Validation 1.0.0-preview.6

This is a prerelease version of Tolitech.Application.Validation.
dotnet add package Tolitech.Application.Validation --version 1.0.0-preview.6
                    
NuGet\Install-Package Tolitech.Application.Validation -Version 1.0.0-preview.6
                    
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="Tolitech.Application.Validation" Version="1.0.0-preview.6" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Tolitech.Application.Validation" Version="1.0.0-preview.6" />
                    
Directory.Packages.props
<PackageReference Include="Tolitech.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 Tolitech.Application.Validation --version 1.0.0-preview.6
                    
#r "nuget: Tolitech.Application.Validation, 1.0.0-preview.6"
                    
#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 Tolitech.Application.Validation@1.0.0-preview.6
                    
#: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=Tolitech.Application.Validation&version=1.0.0-preview.6&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Tolitech.Application.Validation&version=1.0.0-preview.6&prerelease
                    
Install as a Cake Tool

Tolitech.Application.Validation

Overview

Tolitech.Application.Validation is a .NET library that provides a pipeline behavior for MediatR, enabling automatic validation of requests using FluentValidation before they reach their handlers. It helps enforce business rules, improve code quality, and maintain a clean architecture.

Features

  • ValidationBehavior: Pipeline behavior for MediatR that validates requests using registered FluentValidation validators.
  • Error Aggregation: Collects validation errors and returns them in a standardized result format.
  • Integration with Tolitech.Results: Returns validation errors using the Result type for consistency.
  • Localization Support: Error messages can be localized using resource files.
  • Extensibility: Easily add custom validators for any request type.

Main Class

ValidationBehavior<TRequest, TResponse>

Validates requests before passing them to the next handler.

public sealed class ValidationBehavior<TRequest, TResponse>(IEnumerable<IValidator<TRequest>> validators)
    : IPipelineBehavior<TRequest, TResponse>
    where TRequest : IRequest<TResponse>
    where TResponse : Result
Example Usage
1. Define a Request and Validator
public class CreateOrderCommand : IRequest<Result>
{
    public string ProductId { get; set; }
    public int Quantity { get; set; }
}

public class CreateOrderCommandValidator : AbstractValidator<CreateOrderCommand>
{
    public CreateOrderCommandValidator()
    {
        RuleFor(x => x.ProductId).NotEmpty();
        RuleFor(x => x.Quantity).GreaterThan(0);
    }
}
2. Register Validators and Pipeline Behavior
services.AddValidatorsFromAssemblyContaining<CreateOrderCommandValidator>();
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ValidationBehavior<,>));
3. Using MediatR
var result = await mediator.Send(new CreateOrderCommand { ProductId = "A1", Quantity = 0 });
if (!result.IsValid)
{
    // Handle validation errors
    foreach (var error in result.Errors)
    {
        Console.WriteLine($"{error.Key}: {error.Message}");
    }
}

Integration Steps

  1. Reference Tolitech.Application.Validation in your project.
  2. Create FluentValidation validators for your requests.
  3. Register validators and ValidationBehavior in your DI container.
  4. Use MediatR to send requests; validation will be automatic.

Summary

Tolitech.Application.Validation automates request validation in MediatR pipelines, improving reliability and maintainability in .NET applications.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0-preview.6 431 7/21/2025
1.0.0-preview.5 115 7/7/2025
1.0.0-preview.4 117 7/3/2025
1.0.0-preview.3 121 7/3/2025
1.0.0-preview.2 96 12/13/2024
1.0.0-preview.1 71 12/11/2024