Fluent.Unions.Mediator 1.1.0

dotnet add package Fluent.Unions.Mediator --version 1.1.0
                    
NuGet\Install-Package Fluent.Unions.Mediator -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.Mediator" 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.Mediator" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Fluent.Unions.Mediator" />
                    
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.Mediator --version 1.1.0
                    
#r "nuget: Fluent.Unions.Mediator, 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.Mediator@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.Mediator&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Fluent.Unions.Mediator&version=1.1.0
                    
Install as a Cake Tool

Fluent.Unions

Fluent.Unions.Mediator

NuGet Downloads Publish Documentation

Pipeline behaviors for the source-generated Mediator library (MIT) that return a failed Result<T> instead of throwing. They build on Fluent.Unions and work with requests whose response is a C# 15 union.

Installation

dotnet add package Fluent.Unions.Mediator

The package depends on Mediator.Abstractions. Your application also references Mediator.SourceGenerator, as Mediator requires.

Usage

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

using Fluent.Unions.Mediator;

services.AddMediator(options =>
{
    options.PipelineBehaviors = [typeof(ExceptionToResultBehavior<,>), 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 mediator.Send(new CreateUser("", 0));
// error: ValidationErrors for "Name" and "Age"; the handler did not run
  • ExceptionToResultBehavior<TMessage, TResponse> returns an exception thrown by the handler or a later behavior as the error. OperationCanceledException still throws.
  • ValidationToResultBehavior<TMessage, 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.

A request that returns the value-less result needs it declared explicitly next to Result<T>, because the Mediator source generator cannot see types that another generator emits.

[FluentResult<DomainException>]
public readonly partial struct Result<T>;

[FluentResult<DomainException>]
public readonly partial struct Result;

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 94 11/22/2026
1.0.0 97 11/21/2026
0.3.0 98 11/20/2026