Minicon.Mediator 2.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Minicon.Mediator --version 2.1.0
                    
NuGet\Install-Package Minicon.Mediator -Version 2.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="Minicon.Mediator" Version="2.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Minicon.Mediator" Version="2.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Minicon.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 Minicon.Mediator --version 2.1.0
                    
#r "nuget: Minicon.Mediator, 2.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 Minicon.Mediator@2.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=Minicon.Mediator&version=2.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Minicon.Mediator&version=2.1.0
                    
Install as a Cake Tool

Minicon.Mediator

A lightweight, MediatR-API-compatible mediator for .NET — request/response, streaming, notifications and pipeline behaviors with exactly one runtime dependency (Microsoft.Extensions.DependencyInjection.Abstractions).

Independent reimplementation by minicon eG. Not affiliated with or endorsed by the MediatR project. "MediatR" is a trademark of its respective owner; the familiar type names (IRequest, INotification, …) are kept for an easy migration, but this package lives in its own Minicon.Mediator namespace.

Install

dotnet add package Minicon.Mediator

Targets net10.0.

Usage

using Minicon.Mediator;
using Microsoft.Extensions.DependencyInjection;

// 1) Register — scans the given assembly for handlers
services.AddMediator(cfg => cfg.RegisterServicesFromAssemblyContaining<Ping>());

// 2) Request / Response
public 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}");
}

var answer = await mediator.Send(new Ping("hi"));   // "Pong: hi"

// 3) Notifications (fan-out to all handlers)
public record UserRegistered(string Email) : INotification;

public sealed class SendWelcome : INotificationHandler<UserRegistered>
{
    public Task Handle(UserRegistered n, CancellationToken ct) => /* ... */ Task.CompletedTask;
}

await mediator.Publish(new UserRegistered("a@b.de"));

// 4) Pipeline behaviors (logging, validation, transactions, …)
public sealed class LoggingBehavior<TReq, TRes> : IPipelineBehavior<TReq, TRes>
    where TReq : notnull
{
    public async Task<TRes> Handle(TReq req, RequestHandlerDelegate<TRes> next, CancellationToken ct)
    {
        // before
        var res = await next();
        // after
        return res;
    }
}

Streaming

For handlers that produce many responses over time, use IStreamRequest<T> and CreateStream. Elements are forwarded as the handler yields them — nothing is buffered, so the consumer can break out early or cancel at any point.

public record Tail(string File) : IStreamRequest<string>;

public sealed class TailHandler : IStreamRequestHandler<Tail, string>
{
    public async IAsyncEnumerable<string> Handle(Tail request, [EnumeratorCancellation] CancellationToken ct)
    {
        await foreach (var line in File.ReadLinesAsync(request.File, ct))
        {
            yield return line;
        }
    }
}

await foreach (var line in mediator.CreateStream(new Tail("app.log"), ct))
{
    Console.WriteLine(line);
}

Streams have their own behavior interface, IStreamPipelineBehavior<TReq, TRes>, which wraps the handler the same way IPipelineBehavior<,> does for Send:

public sealed class CountingBehavior<TReq, TRes> : IStreamPipelineBehavior<TReq, TRes>
    where TReq : notnull
{
    public async IAsyncEnumerable<TRes> Handle(
        TReq req, StreamHandlerDelegate<TRes> next, [EnumeratorCancellation] CancellationToken ct)
    {
        var count = 0;
        await foreach (var item in next(ct).WithCancellation(ct))
        {
            count++;
            yield return item;
        }
        // after — count is complete here
    }
}

Handlers are discovered by the same assembly scan as IRequestHandler<,>; stream behaviors are registered manually (services.AddTransient<IStreamPipelineBehavior<…>, …>()).

Migrating from MediatR

In most cases a single replacement is enough:

  • using MediatR; → using Minicon.Mediator;
  • services.AddMediatR(...) → services.AddMediator(...)
  • MediatRServiceConfiguration → MediatorServiceConfiguration

All other type names (IRequest, IRequest<T>, IStreamRequest<T>, INotification, IRequestHandler<,>, IStreamRequestHandler<,>, INotificationHandler<>, IPipelineBehavior<,>, IStreamPipelineBehavior<,>, ISender, IPublisher, IMediator, Unit) are unchanged.

License

MIT © minicon eG

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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
3.0.0 130 8/21/2026
2.3.0 111 8/21/2026
2.2.0 116 8/21/2026
2.1.0 110 8/17/2026
2.0.0 136 8/17/2026
1.0.0 138 6/8/2026