Skip to content

Mediant

MediatR is now commercially licensed. Mediant is MIT — free, forever — with a built-in Result pattern, 11 pipeline behaviors, Native AOT, and up to 65% faster notification dispatch.

Install

Terminal window
dotnet add package Mediant
// 1. Register
builder.Services.AddMediant(cfg =>
cfg.RegisterServicesFromAssembly(typeof(Program).Assembly));
// 2. Define a command — explicit CQRS, not just IRequest
public record CreateOrder(string UserId) : ICommand<Result<Guid>>;
// 3. Handle it — ValueTask + Result, no exceptions for control flow
public class CreateOrderHandler : ICommandHandler<CreateOrder, Result<Guid>>
{
public ValueTask<Result<Guid>> Handle(CreateOrder cmd, CancellationToken ct)
=> new(Result<Guid>.Success(Guid.NewGuid()));
}
// 4. Send it
var result = await mediator.Send(new CreateOrder("user-1"));
result.Match(id => Ok(id), error => Problem(error.Description));

Faster where it counts

Measured with BenchmarkDotNet against MediatR v12.4.1 on .NET 10 (Apple M5). These isolate framework dispatch overhead with no-op handlers — see the full method and results.

Publish (notification dispatch)

HandlersMediantMediatR v12
124 ns / 88 B44 ns / 288 B46% faster · 3.3× less memory
1069 ns / 376 B184 ns / 1,656 B63% faster · 4.4× less memory
100527 ns / 3,256 B1,521 ns / 15,336 B65% faster · 4.7× less memory

Send (pipeline) is within noise up to 4 behaviors, then Mediant pulls ahead — and allocates less in every scenario.

MIT licensed

Free for any use, forever. No commercial tier, no seat counting.

Result pattern built in

Result<T> and typed Errors — no throwing exceptions for control flow. Map, Bind, Match.

Explicit CQRS

ICommand<T> and IQuery<T> instead of one IRequest. Streaming via IStreamRequest<T>.

11 built-in behaviors

Audit, logging, validation, authorization, idempotency, transactions, retry, caching, cache invalidation, performance — attribute-driven, explicitly ordered.

Native AOT & trimming

A source generator precomputes handler registration and dispatch at compile time — no assembly scanning, no runtime codegen.

OpenTelemetry

Traces and metrics from System.Diagnostics primitives, with zero cost when nothing listens.

HTTP endpoints

[HttpEndpoint] maps a command straight to a route — no controller boilerplate. Result maps to the right status code.

300 tests

Unit, integration, load (50K concurrent) and E2E. Roslyn analyzers catch attribute misuse at compile time.

Used in production

Mediant is the CQRS layer inside Mockifyr, an API mock engine whose correctness is proven differentially against a reference oracle. Dogfooded, not demoware.