XForge.MediatR.SourceGenerators 1.0.7

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

XForge.MediatR

XForge.MediatR

Simple, fluent, in-process mediator for .NET with CQRS, pipeline behaviors, and local events.

NuGet Version NuGet Downloads CI .NET MIT License


Why XForge.MediatR?

A modern alternative to MediatR with explicit CQRS, ValueTask contracts, behavior ordering, built-in resilience, and TestableMediator — all under MIT license.

Feature XForge.MediatR MediatR
ValueTask on contracts
Explicit CQRS (ICommand, IQuery)
Behavior ordering & filtering
TestableMediator (no DI)
Result<T> monad
Retry + Circuit Breaker + Rate Limiter
Roslyn analyzer
OpenTelemetry package
Source generator for handlers
MIT license (no license key)

Quick Start

dotnet add package XForge.MediatR.DependencyInjection
// 1. Define a query
public record GetOrder(int OrderId) : IQuery<OrderDto>;
public record OrderDto(int Id, string Customer, decimal Total);

// 2. Implement the handler
public class GetOrderHandler : IRequestHandler<GetOrder, OrderDto>
{
    public ValueTask<OrderDto> Handle(GetOrder request, CancellationToken ct)
        => ValueTask.FromResult(new OrderDto(request.OrderId, "Acme Corp", 250.00m));
}

// 3. Register and use
builder.Services.AddXForgeMediator(cfg =>
{
    cfg.RegisterHandlersFrom<Program>();
    cfg.UseDefaults(); // Validation + Logging + Metrics
});

app.MapGet("/orders/{id}", async (int id, IXForgeMediator mediator) =>
    Results.Ok(await mediator.Send(new GetOrder(id))));

Packages

Package Description Dependencies
XForge.MediatR Core mediator + pipeline + behaviors DI.Abstractions, Logging.Abstractions
XForge.MediatR.Abstractions Contracts and interfaces (zero dependencies) None
XForge.MediatR.DependencyInjection DI extensions + fluent configuration API DI.Abstractions
XForge.MediatR.Testing TestableMediator for unit tests without DI None (Abstractions only)
XForge.MediatR.SourceGenerators Compile-time handler discovery + Roslyn analyzer None (netstandard2.0)
XForge.MediatR.OpenTelemetry Traces + metrics via OpenTelemetry OpenTelemetry
XForge.MediatR.AspNetCore ASP.NET Core integration (model binding) AspNetCore.Mvc.Core
XForge.MediatR.Validation FluentValidation adapter FluentValidation
XForge.MediatR.EntityFrameworkCore EF Core transaction behavior EntityFrameworkCore
XForge.MediatR.Outbox Outbox pattern for deferred event publishing None (Abstractions only)

Key Features

  • CQRS ExplícitoICommand<T>, IQuery<T>, IEvent with semantic separation
  • Flat Pipeline — behaviors with explicit ordering (IOrdered) and filtering (UseFor<T>, UseWhen)
  • Built-in Behaviors — validation, logging, metrics, retry, circuit breaker, rate limiter, concurrency limiter, exception handling, pre/post processors
  • Result<T> — typed success/failure without exceptions
  • StreamingIStreamRequest<T> with IAsyncEnumerable<T> and pipeline support
  • TestableMediator — builder pattern for testing without DI container
  • Source Generator — compile-time handler registration, zero reflection at startup
  • Roslyn AnalyzerXFMR001 (duplicate handler), XFMR002 (void mismatch), XFMR003 (event handler return type)
  • OpenTelemetry — vendor-agnostic traces and metrics
  • Multi-TFM — targets net8.0, net9.0, net10.0

Built-in Behaviors

Behavior Order Description
ConcurrencyLimiter -325 SemaphoreSlim concurrency control
RateLimiter -320 Fixed-window rate limiting
CircuitBreaker -310 Opens circuit after consecutive failures
Retry -300 Exponential/linear/constant backoff
Authorization -280 Handler-level authorization checks
Idempotency -290 Idempotent request processing
MultiTenant -260 Tenant validation
ExceptionHandling -250 Typed exception handlers
Validation -200 FluentValidation integration
PrePostProcessors -150 Pre/post handler hooks
Logging -100 High-performance structured logging
Diagnostics -75 Activity enrichment
PerformanceMetrics -50 Duration measurement + Activity spans
Audit -40 Audit trail via IAuditSink
Caching -30 Query result caching
Transaction -15 TransactionScope for commands

Performance

Benchmarked on .NET 10.0.8, x64 RyuJIT AVX2 against MediatR 14.1.0 and Mediator 3.0.2 (source-generator):

Operation XForge.MediatR MediatR Mediator (source-gen)
Send 61 ns / 120 B 72 ns / 296 B 21 ns / 96 B
Publish 161 ns / 88 B 392 ns / 1248 B 27 ns / 0 B
Pipeline (0 beh) 79 ns / 120 B 74 ns / 296 B
Pipeline (3 beh) 671 ns / 1024 B 150 ns / 608 B
Cold Start ~6 µs ~174 µs ~14 µs

Highlights:

  • Send 1.18x faster than MediatR with 59% less allocation (120 B vs 296 B)
  • Publish 2.43x faster than MediatR with 14x less allocation
  • Cold Start 29x faster than MediatR — ideal for serverless
  • Zero tracing overhead — ActivitySource short-circuits when no listeners

See Performance & Benchmarks for full details.

Documentation

Requirements

Requirement Version
.NET SDK 8.0+
C# 12+
IDE Visual Studio 2022 17.8+, Rider 2023.3+, or VS Code with C# extension

License

MIT — Copyright (c) XForge

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has 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
1.0.7 91 5/25/2026
1.0.6 82 5/25/2026
1.0.5 90 5/24/2026
1.0.4 89 5/24/2026
1.0.3 88 5/24/2026
1.0.2 88 5/24/2026
1.0.1 96 5/23/2026