JAAvila.FluentOperations.MediatR 1.5.0

dotnet add package JAAvila.FluentOperations.MediatR --version 1.5.0
                    
NuGet\Install-Package JAAvila.FluentOperations.MediatR -Version 1.5.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="JAAvila.FluentOperations.MediatR" Version="1.5.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="JAAvila.FluentOperations.MediatR" Version="1.5.0" />
                    
Directory.Packages.props
<PackageReference Include="JAAvila.FluentOperations.MediatR" />
                    
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 JAAvila.FluentOperations.MediatR --version 1.5.0
                    
#r "nuget: JAAvila.FluentOperations.MediatR, 1.5.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 JAAvila.FluentOperations.MediatR@1.5.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=JAAvila.FluentOperations.MediatR&version=1.5.0
                    
Install as a Cake Addin
#tool nuget:?package=JAAvila.FluentOperations.MediatR&version=1.5.0
                    
Install as a Cake Tool

JAAvila.FluentOperations.MediatR

MediatR integration for JAAvila.FluentOperations Quality Blueprints. Provides pipeline behaviors that automatically validate requests before they reach your handlers.

Installation

dotnet add package JAAvila.FluentOperations.MediatR

Note: This package targets MediatR 12.x (Apache 2.0). MediatR 13+ changed its license to RPL-1.5 and is not supported.

Quick Start

1. Define a Blueprint for your request

public class CreateOrderCommand : IRequest<OrderResult>
{
    public string CustomerName { get; set; }
    public int Quantity { get; set; }
}

public class CreateOrderBlueprint : QualityBlueprint<CreateOrderCommand>
{
    public CreateOrderBlueprint()
    {
        For(x => x.CustomerName).NotBeNullOrWhiteSpace().HaveMinLength(2);
        For(x => x.Quantity).BePositive().BeLessThan(1000);
    }
}

2. Register in DI

Automatic discovery (validates all requests that have a matching blueprint):

builder.Services
    .AddSingleton<QualityBlueprint<CreateOrderCommand>, CreateOrderBlueprint>()
    .AddBlueprintValidation(); // registers the open-generic pipeline behavior

Strongly typed (explicit binding between request and blueprint):

builder.Services.AddBlueprintBehavior<CreateOrderCommand, OrderResult, CreateOrderBlueprint>();

Base-class blueprints (validate derived request types with a shared blueprint):

public class BaseOrderBlueprint : QualityBlueprint<BaseOrder> { ... }

builder.Services.AddBlueprintBehavior<CreateOrderCommand, OrderResult, BaseOrder, BaseOrderBlueprint>();

3. Send requests as usual

// If validation fails, a BlueprintValidationException is thrown
// before the handler executes
var result = await mediator.Send(new CreateOrderCommand
{
    CustomerName = "",
    Quantity = -1
});

Behavior on Validation Failure

When a request fails validation, the behavior throws a BlueprintValidationException containing the full QualityReport with all failures. You can catch this in your exception handling middleware:

try
{
    var result = await mediator.Send(command);
}
catch (BlueprintValidationException ex)
{
    QualityReport report = ex.Report;
    // report.Failures contains property names, messages, and attempted values
}

Registration Approaches

Three approaches are available. Choose based on how your blueprint relates to the request:

services.AddSingleton<QualityBlueprint<CreateOrderCommand>, CreateOrderBlueprint>();
services.AddBlueprintValidation();

Discovers matching blueprints at runtime. Works regardless of whether the blueprint models the request type directly or a base type.

2. Direct request validation (3-generic)

Use when your blueprint validates the request type directly (TBlueprint : QualityBlueprint<TRequest>):

// Blueprint: public class CreateOrderBlueprint : QualityBlueprint<CreateOrderCommand>
services.AddBlueprintBehavior<CreateOrderCommand, OrderResult, CreateOrderBlueprint>();

3. Base model validation (4-generic)

Use when your blueprint validates a base model and the request inherits from it:

// Blueprint: public class UserBlueprint : QualityBlueprint<User>
// Request:   public class CreateUserCommand : User, IRequest<string>
services.AddBlueprintBehavior<CreateUserCommand, string, User, UserBlueprint>();

Note: Using the 3-generic overload with a base-model blueprint causes a compile error because TBlueprint : QualityBlueprint<TRequest> is not satisfied. Use the 4-generic overload or auto-discovery instead.

API Reference

Method Description
AddBlueprintValidation() Registers the open-generic MediatRBlueprintBehavior<,> for all requests
AddBlueprintBehavior<TRequest, TResponse, TBlueprint>() Registers a strongly typed behavior. Blueprint must validate the request type directly.
AddBlueprintBehavior<TRequest, TResponse, TModel, TBlueprint>() Registers a behavior where TRequest derives from TModel and the blueprint validates TModel

Features

  • Automatic hierarchy walk: the open-generic behavior resolves QualityBlueprint<T> by walking up the request's type hierarchy, supporting base-class blueprints out of the box.
  • Async validation: uses CheckAsync for non-blocking validation in the pipeline.
  • Strongly typed option: MediatRBlueprintBehavior<TRequest, TResponse, TBlueprint> for compile-time safety when the request type matches the blueprint exactly.

Requirements

Dependency Version
.NET 8.0+
JAAvila.FluentOperations (same major version)
MediatR >= 12.4.1, < 13.0.0

License

Apache-2.0

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 was computed.  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.5.0 90 3/29/2026
1.3.0 88 3/26/2026
1.1.0 85 3/21/2026
1.0.1 93 3/9/2026
1.0.1-alpha.0.1 46 3/9/2026
1.0.0 84 3/9/2026