Pitasoft.FluentValidation.AspNetCore 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Pitasoft.FluentValidation.AspNetCore --version 1.0.1
                    
NuGet\Install-Package Pitasoft.FluentValidation.AspNetCore -Version 1.0.1
                    
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="Pitasoft.FluentValidation.AspNetCore" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Pitasoft.FluentValidation.AspNetCore" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Pitasoft.FluentValidation.AspNetCore" />
                    
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 Pitasoft.FluentValidation.AspNetCore --version 1.0.1
                    
#r "nuget: Pitasoft.FluentValidation.AspNetCore, 1.0.1"
                    
#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 Pitasoft.FluentValidation.AspNetCore@1.0.1
                    
#: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=Pitasoft.FluentValidation.AspNetCore&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Pitasoft.FluentValidation.AspNetCore&version=1.0.1
                    
Install as a Cake Tool

Pitasoft.FluentValidation.AspNetCore

NuGet NuGet Downloads Build Status License .NET Versions FluentValidation Pitasoft.FluentValidation Pitasoft.Result.AspNetCore


English | Castellano


English

Pitasoft.FluentValidation.AspNetCore integrates FluentValidation into ASP.NET Core request pipelines using endpoint filters for Minimal API and action filters for MVC / Web API.

When request validation fails, the package converts the errors into Result.ValidationError(...) and delegates HTTP serialization to Pitasoft.Result.AspNetCore, returning 400 Bad Request.

Features

  • Minimal API integration with WithValidator<T>()
  • Minimal API integration with WithValidator<T>(instance)
  • MVC / Web API integration with [ValidateRequest<T>]
  • Validation output translated to Pitasoft.Result.ValidationError(...)
  • Compatible with Pitasoft.Result.AspNetCore response formatting
  • Preserves FluentValidation property paths such as Name, Address.City, or Items[0].Name

Installation

dotnet add package Pitasoft.FluentValidation.AspNetCore

Dependency injection

Register your FluentValidation validators in ASP.NET Core DI before using the filters:

using FluentValidation;

builder.Services.AddScoped<IValidator<CreateProductRequest>, CreateProductRequestValidator>();

Minimal API example with DI

using FluentValidation;
using Microsoft.AspNetCore.Mvc;
using Pitasoft.FluentValidation.AspNetCore.Extensions;
using Pitasoft.Result;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddScoped<IValidator<CreateProductRequest>, CreateProductRequestValidator>();

var app = builder.Build();

app.MapPost("/products", ([FromBody] CreateProductRequest request) =>
    Result.Ok())
   .WithValidator<CreateProductRequest>();

app.Run();

public sealed record CreateProductRequest(string? Name, decimal Price);

public sealed class CreateProductRequestValidator : AbstractValidator<CreateProductRequest>
{
    public CreateProductRequestValidator()
    {
        RuleFor(x => x.Name)
            .NotEmpty()
            .WithMessage("Name is required.");

        RuleFor(x => x.Price)
            .GreaterThan(0)
            .WithMessage("Price must be greater than 0.");
    }
}

Minimal API example with inline validator

This is useful when you want to attach a concrete validator instance directly to one endpoint:

using FluentValidation;
using Pitasoft.FluentValidation.AspNetCore.Extensions;
using Pitasoft.Result;

var app = WebApplication.Create();

app.MapPost("/products", (CreateProductRequest request) =>
    Result.Ok())
   .WithValidator(new CreateProductRequestValidator());

app.Run();

MVC / Web API example

using FluentValidation;
using Microsoft.AspNetCore.Mvc;
using Pitasoft.FluentValidation.AspNetCore.Attributes;
using Pitasoft.Result;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllers();
builder.Services.AddScoped<IValidator<CreateProductRequest>, CreateProductRequestValidator>();

var app = builder.Build();
app.MapControllers();
app.Run();

[ApiController]
[Route("api/products")]
public sealed class ProductsController : ControllerBase
{
    [HttpPost]
    [ValidateRequest<CreateProductRequest>]
    public object Create([FromBody] CreateProductRequest request)
    {
        return Result.Ok();
    }
}

public sealed record CreateProductRequest(string? Name, decimal Price);

public sealed class CreateProductRequestValidator : AbstractValidator<CreateProductRequest>
{
    public CreateProductRequestValidator()
    {
        RuleFor(x => x.Name).NotEmpty().WithMessage("Name is required.");
        RuleFor(x => x.Price).GreaterThan(0).WithMessage("Price must be greater than 0.");
    }
}

What happens on validation failure

If the validator reports errors:

  • the pipeline is short-circuited
  • the package creates Result.ValidationError(errors)
  • Pitasoft.Result.AspNetCore converts it to the HTTP response
  • the HTTP status code is 400 Bad Request

Notes about Pitasoft.FluentValidation

This package is designed to live in the Pitasoft ecosystem and depends on Pitasoft.FluentValidation.

At the HTTP boundary, filters work directly with FluentValidation.IValidator<T> so they can preserve ASP.NET-specific behavior such as request cancellation and async validation execution, while still remaining aligned with the wider Pitasoft validation stack.

Public API

Minimal API:

  • WithValidator<T>()
  • WithValidator<T>(IValidator<T> validator)

MVC / Web API:

  • [ValidateRequest<T>]

Validation behavior

  • The first request argument compatible with T is validated
  • Null compatible arguments are also considered for validation
  • Validation errors are preserved as structured ErrorCollection
  • ProblemDetails is not used as the default contract

Requirements

  • ASP.NET Core 8, 9 or 10
  • FluentValidation
  • Pitasoft.FluentValidation
  • Pitasoft.Result.AspNetCore

Castellano

Pitasoft.FluentValidation.AspNetCore integra FluentValidation en la tubería de ASP.NET Core usando filtros de endpoint para Minimal API y filtros de acción para MVC / Web API.

Cuando la validación de la petición falla, el paquete convierte los errores en Result.ValidationError(...) y delega la serialización HTTP a Pitasoft.Result.AspNetCore, devolviendo 400 Bad Request.

Características

  • Integración con Minimal API mediante WithValidator<T>()
  • Integración con Minimal API mediante WithValidator<T>(instancia)
  • Integración con MVC / Web API mediante [ValidateRequest<T>]
  • Los errores de validación se traducen a Pitasoft.Result.ValidationError(...)
  • Compatible con el formateo de respuestas de Pitasoft.Result.AspNetCore
  • Conserva rutas de propiedad de FluentValidation como Name, Address.City o Items[0].Name

Instalación

dotnet add package Pitasoft.FluentValidation.AspNetCore

Inyección de dependencia

Registra tus validadores de FluentValidation en el contenedor DI de ASP.NET Core antes de usar los filtros:

using FluentValidation;

builder.Services.AddScoped<IValidator<CreateProductRequest>, CreateProductRequestValidator>();

Ejemplo con Minimal API usando DI

using FluentValidation;
using Microsoft.AspNetCore.Mvc;
using Pitasoft.FluentValidation.AspNetCore.Extensions;
using Pitasoft.Result;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddScoped<IValidator<CreateProductRequest>, CreateProductRequestValidator>();

var app = builder.Build();

app.MapPost("/products", ([FromBody] CreateProductRequest request) =>
    Result.Ok())
   .WithValidator<CreateProductRequest>();

app.Run();

public sealed record CreateProductRequest(string? Name, decimal Price);

public sealed class CreateProductRequestValidator : AbstractValidator<CreateProductRequest>
{
    public CreateProductRequestValidator()
    {
        RuleFor(x => x.Name)
            .NotEmpty()
            .WithMessage("El nombre es obligatorio.");

        RuleFor(x => x.Price)
            .GreaterThan(0)
            .WithMessage("El precio debe ser mayor que cero.");
    }
}

Ejemplo con Minimal API usando instancia inline

Es útil cuando quieres asociar una instancia concreta del validador directamente a un endpoint:

using FluentValidation;
using Pitasoft.FluentValidation.AspNetCore.Extensions;
using Pitasoft.Result;

var app = WebApplication.Create();

app.MapPost("/products", (CreateProductRequest request) =>
    Result.Ok())
   .WithValidator(new CreateProductRequestValidator());

app.Run();

Ejemplo con MVC / Web API

using FluentValidation;
using Microsoft.AspNetCore.Mvc;
using Pitasoft.FluentValidation.AspNetCore.Attributes;
using Pitasoft.Result;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllers();
builder.Services.AddScoped<IValidator<CreateProductRequest>, CreateProductRequestValidator>();

var app = builder.Build();
app.MapControllers();
app.Run();

[ApiController]
[Route("api/products")]
public sealed class ProductsController : ControllerBase
{
    [HttpPost]
    [ValidateRequest<CreateProductRequest>]
    public object Create([FromBody] CreateProductRequest request)
    {
        return Result.Ok();
    }
}

public sealed record CreateProductRequest(string? Name, decimal Price);

public sealed class CreateProductRequestValidator : AbstractValidator<CreateProductRequest>
{
    public CreateProductRequestValidator()
    {
        RuleFor(x => x.Name).NotEmpty().WithMessage("El nombre es obligatorio.");
        RuleFor(x => x.Price).GreaterThan(0).WithMessage("El precio debe ser mayor que cero.");
    }
}

Qué ocurre cuando falla la validación

Si el validador devuelve errores:

  • la tubería HTTP se corta antes de ejecutar el endpoint o la acción
  • el paquete crea Result.ValidationError(errors)
  • Pitasoft.Result.AspNetCore lo convierte en respuesta HTTP
  • el código de estado HTTP es 400 Bad Request

Notas sobre Pitasoft.FluentValidation

Este paquete está pensado para convivir en el ecosistema Pitasoft y depende de Pitasoft.FluentValidation.

En la frontera HTTP, los filtros trabajan directamente con FluentValidation.IValidator<T> para conservar correctamente el comportamiento específico de ASP.NET, como la cancelación de petición y la validación asíncrona, manteniéndose al mismo tiempo alineados con el stack de validación de Pitasoft.

API pública

Minimal API:

  • WithValidator<T>()
  • WithValidator<T>(IValidator<T> validator)

MVC / Web API:

  • [ValidateRequest<T>]

Comportamiento de validación

  • Se valida el primer argumento de la petición compatible con T
  • Los argumentos compatibles con valor null también se tienen en cuenta
  • Los errores de validación se conservan como ErrorCollection
  • ProblemDetails no se usa como contrato por defecto

Requisitos

  • ASP.NET Core 8, 9 o 10
  • FluentValidation
  • Pitasoft.FluentValidation
  • Pitasoft.Result.AspNetCore

Author

Sebastián Martínez Pérez

License

Copyright © 2026 Pitasoft, S.L. Distributed under the license included in LICENSE.txt.

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

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.3 128 4/3/2026
1.0.2 119 4/3/2026
1.0.1 125 4/1/2026