Mediarq.MediatRCompat
1.5.1
dotnet add package Mediarq.MediatRCompat --version 1.5.1
NuGet\Install-Package Mediarq.MediatRCompat -Version 1.5.1
<PackageReference Include="Mediarq.MediatRCompat" Version="1.5.1" />
<PackageVersion Include="Mediarq.MediatRCompat" Version="1.5.1" />
<PackageReference Include="Mediarq.MediatRCompat" />
paket add Mediarq.MediatRCompat --version 1.5.1
#r "nuget: Mediarq.MediatRCompat, 1.5.1"
#:package Mediarq.MediatRCompat@1.5.1
#addin nuget:?package=Mediarq.MediatRCompat&version=1.5.1
#tool nuget:?package=Mediarq.MediatRCompat&version=1.5.1
Mediarq.MediatRCompat
An optional compatibility shim so you can migrate to Mediarq incrementally: keep your existing
MediatR.IRequest/IRequestHandler/INotification/INotificationHandler/IStreamRequest/
IStreamRequestHandler classes completely unchanged, wire them through Mediarq's own dispatch pipeline,
and convert handlers to native Mediarq types file by file (e.g. with Mediarq.Analyzers) at your own pace.
dotnet add package Mediarq.MediatRCompat
Usage
Register it in addition to (after) AddMediarq/AddMediarqCore, which must already have configured
Mediarq's own dispatch services:
builder.Services.AddMediarq(isHttp: true, typeof(Program).Assembly)
.AddMediarqMediatRCompat(typeof(Program).Assembly);
AddMediarqMediatRCompat scans the given assemblies for classes implementing MediatR's own
IRequestHandler<,> / IRequestHandler<> / INotificationHandler<> / IStreamRequestHandler<,>, and
registers each behind a MediatRCompatMediator that dispatches through Mediarq's real
ISender/IPublisher — so your existing handlers run through the same pipeline behaviors (validation,
logging, ...) as native Mediarq requests.
Inject MediatR.IMediator (or ISender/IPublisher) exactly as you did with MediatR — no source change
needed in the classes that send requests or publish notifications, either:
public sealed class Ping(string Message) : MediatR.IRequest<string>;
public sealed class PingHandler : MediatR.IRequestHandler<Ping, string>
{
public Task<string> Handle(Ping request, CancellationToken ct) => Task.FromResult(request.Message);
}
// Unchanged call site:
var response = await mediator.Send(new Ping("hi"));
The runtime-typed Send(object) / Publish(object) / CreateStream(object) overloads MediatR itself
exposes are supported too (useful for generic infrastructure code that doesn't know the request type at
compile time).
What isn't bridged
This shim covers requests, handlers, notifications and streaming — the same surface
Mediarq.Analyzers' migration analyzer targets. It does not bridge MediatR's IPipelineBehavior<,>,
IRequestPreProcessor<>/IRequestPostProcessor<,>, or IRequestExceptionHandler<,,>: their signatures
differ enough from Mediarq's own that converting them is left as a manual step even in a full rewrite —
see Migrating from MediatR.
Write any new cross-cutting behavior directly against Mediarq's IPipelineBehavior<,>.
Note on performance
Because a MediatR-shaped request's concrete type is only known at runtime, dispatching it requires reflection once per concrete type (the result is cached — subsequent calls for the same type are reflection-free). This is an explicit migration/compatibility path, not the Native-AOT hot path: convert a handler to a native Mediarq type when you want fully reflection-free dispatch for it.
Learn more
Mediarq.Analyzers · Migrating from MediatR · Full README
MIT © Nicolas Rouffart
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. 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. |
-
net10.0
- Mediarq.Core (>= 1.5.1)
- MediatR (>= 12.4.1)
-
net8.0
- Mediarq.Core (>= 1.5.1)
- MediatR (>= 12.4.1)
-
net9.0
- Mediarq.Core (>= 1.5.1)
- MediatR (>= 12.4.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.