Fluent.Unions.MediatR 1.1.0

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

Fluent.Unions

Fluent.Unions.MediatR

NuGet Downloads Publish Documentation

Pipeline behaviors for MediatR that return a failed Result<T> instead of throwing. They build on Fluent.Unions.

License of MediatR

This package depends on MediatR 15, which is dual licensed: the Reciprocal Public License 1.5 (RPL-1.5) or a commercial license from Lucky Penny Software. Check that the license fits your project before you use it. Fluent.Unions.MediatR itself has the license of this repository. For a permissive alternative, see Fluent.Unions.Mediator.

Installation

dotnet add package Fluent.Unions.MediatR

Usage

Register the behaviors as open generics. The first one in the list is the outermost.

using Fluent.Unions.MediatR;

services.AddMediatR(configuration =>
{
    configuration.RegisterServicesFromAssemblyContaining<Program>();
    configuration.AddOpenBehavior(typeof(ExceptionToResultBehavior<,>));
    configuration.AddOpenBehavior(typeof(ValidationToResultBehavior<,>));
});

A request whose response is a Result<T> now fails with an error instead of throwing.

public sealed record CreateUser([property: Required] string Name, [property: Range(1, 120)] int Age)
    : IRequest<Result<UserId>>;

Result<UserId> result = await sender.Send(new CreateUser("", 0));
// error: ValidationErrors for "Name" and "Age"; the handler did not run
  • ExceptionToResultBehavior<TRequest, TResponse> returns an exception thrown by the handler or a later behavior as the error. OperationCanceledException still throws.
  • ValidationToResultBehavior<TRequest, TResponse> validates the request with its System.ComponentModel.DataAnnotations attributes and IValidatableObject, and returns ValidationErrors. Put [property: ...] on record parameters.

With your own result type

TResponse can be any result type: Result, Result<T> or your own declared result. The error is what the response type's FromException makes of the exception or of the ValidationErrors. A request with another response type is left alone.

The behaviors use reflection, so they are not trimming or AOT friendly. See your own result type.

Documentation

Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
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.1.0 98 11/22/2026
1.0.0 94 11/21/2026
0.3.0 100 11/20/2026