Personix.Mediator 2.0.0

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

Personix.Mediator

NuGet License: MIT

A lightweight mediator for .NET with keyed dependency-injection support and configurable pipeline behaviors — a free, MIT-licensed take on request/response dispatch and pipeline middleware.

Unlike most mediator libraries, it supports multiple isolated (keyed) mediator instances in the same container, each with its own handlers and behavior pipeline.

Install

dotnet add package Personix.Mediator

Usage

Define a request and its handler:

public sealed record Ping(string Message) : IRequest<string>;

public sealed class PingHandler : IRequestHandler<Ping, string>
{
    public Task<string> Handle(Ping request, CancellationToken ct)
        => Task.FromResult($"pong: {request.Message}");
}

Register and send:

services.AddMediator(cfg =>
{
    cfg.RegisterServicesFromAssembly(typeof(PingHandler).Assembly);
    cfg.AddBehavior(typeof(LoggingBehavior<,>));
});

var sender = provider.GetRequiredService<ISender>();
var reply = await sender.Send(new Ping("hi"));

Pipeline behaviors

Behaviors wrap a request like middleware — pre/post logic, and they can short-circuit the pipeline. Registration order is execution order (first added = outermost).

public sealed class LoggingBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
    where TRequest : notnull
{
    public async Task<TResponse> Handle(
        TRequest request, RequestHandlerDelegate<TResponse> next, CancellationToken ct)
    {
        // before
        var response = await next();
        // after
        return response;
    }
}

Keyed instances

Register several independent mediators, each with its own pipeline, and resolve them by key:

services.AddMediator("admin", cfg =>
{
    cfg.RegisterServicesFromAssembly(typeof(AdminHandler).Assembly);
    cfg.AddBehavior(typeof(AuditBehavior<,>));
});

var adminSender = provider.GetRequiredKeyedService<ISender>("admin");

Keyed and non-keyed mediators coexist; each key has a fully isolated behavior pipeline.

Also in this repository

NuGet

Personix.Mediator.Middleware is a second, independent package whose pipeline steps are ordinary ASP.NET Core middleware. A request travels the real middleware chain and arrives at your endpoint method with no server, no port and no socket behind it, which makes it useful for running many web applications in one process as plain objects.

dotnet add package Personix.Mediator.Middleware

The two packages share no code and neither depends on the other. This one has no runtime dependencies at all, while the middleware package needs the ASP.NET Core shared framework. Keeping them apart is what spares a console, MAUI or Blazor WebAssembly consumer that requirement.

License

MIT © Personix

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.
  • net11.0

    • No dependencies.

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
2.0.0 112 8/30/2026
1.1.0 104 8/27/2026
1.0.1 125 8/1/2026
1.0.0 134 6/28/2026

2.0.0 — targets net11.0. No API change.