Personix.Mediator
2.0.0
dotnet add package Personix.Mediator --version 2.0.0
NuGet\Install-Package Personix.Mediator -Version 2.0.0
<PackageReference Include="Personix.Mediator" Version="2.0.0" />
<PackageVersion Include="Personix.Mediator" Version="2.0.0" />
<PackageReference Include="Personix.Mediator" />
paket add Personix.Mediator --version 2.0.0
#r "nuget: Personix.Mediator, 2.0.0"
#:package Personix.Mediator@2.0.0
#addin nuget:?package=Personix.Mediator&version=2.0.0
#tool nuget:?package=Personix.Mediator&version=2.0.0
Personix.Mediator
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
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 | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
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.
2.0.0 — targets net11.0. No API change.