MoMediator 2.0.3
dotnet add package MoMediator --version 2.0.3
NuGet\Install-Package MoMediator -Version 2.0.3
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="MoMediator" Version="2.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MoMediator" Version="2.0.3" />
<PackageReference Include="MoMediator" />
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 MoMediator --version 2.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: MoMediator, 2.0.3"
#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 MoMediator@2.0.3
#: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=MoMediator&version=2.0.3
#tool nuget:?package=MoMediator&version=2.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
✨ MoMediator Implementation (C#) — v2.0.3
This project provides a fast, extensible implementation of the Mediator pattern in C#, with a focus on performance, lightweight usage, and developer ergonomics.
⬇️ Download
- .NET CLI:
dotnet add package MoMediator --version 2.0.3 - Package Manager:
NuGet\Install-Package MoMediator -Version 2.0.3 - Package Reference:
<PackageReference Include="MoMediator" Version="2.0.3" />
🚀 What's New in 2.0.3
- 🔥 Performance Improvements: Major optimizations for speed and efficiency.
- ⚡ Compiled delegate caching for faster execution (no reflection in hot paths)
- 🧠 Internal caching of handler types and method delegates
- 🔧 Cleaner DI registration with overloads for assemblies and marker types
- 🧼 Less boilerplate for registering handlers
- ✅ Improved handler invocation using expression trees
✨ Features
- ✅ Lightweight and fast: No external dependencies, minimal overhead.
- ✅ Easy to use: Simple API for sending requests and publishing notifications.
- ✅ Flexible: Supports both synchronous and asynchronous handlers.
- ✅ Built-in support for cancellation tokens.
- ✅ Dependency injection friendly: Easily integrates with your existing DI container.
- ✅ Supports generic requests and notifications.
- ✅ Send<TResponse> — Request/Response messaging
- ✅ Publish<TNotification> — Notification broadcasting to multiple handlers
- ✅ Compiled delegates (no reflection at runtime for requests)
🧱 Architecture
MoMediatoR decouples request/notification producers from their handlers via two primary interfaces:
- IRequest<TResponse> – Represents a command/query expecting a response
-
- INotification – Represents an event/notification (fire and forget)
Handlers are discovered at startup and cached for optimal runtime performance.
🧩 Interfaces
public interface IRequest<TResponse> { }
public interface INotification { }
public interface IRequestHandler<TRequest, TResponse>
where TRequest : IRequest<TResponse>
{
Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken);
}
public interface INotificationHandler<TNotification>
where TNotification : INotification
{
Task Handle(TNotification notification, CancellationToken cancellationToken);
}
⚙️ Usage
Example Request & Handler
using MoMediatoR;
public class GetUserQuery : IRequest<UserDto> { }
public class GetUserHandler : IRequestHandler<GetUserQuery, UserDto>
{
public Task<UserDto> Handle(GetUserQuery request, CancellationToken cancellationToken)
{
return Task.FromResult(new UserDto { Name = "John Doe" });
}
}
Example Notification & Handler
using MoMediatoR;
public class UserCreatedNotification : INotification { }
public class UserCreatedHandler : INotificationHandler<UserCreatedNotification>
{
public Task Handle(UserCreatedNotification notification, CancellationToken cancellationToken)
{
Console.WriteLine("User created event handled.");
return Task.CompletedTask;
}
}
Example Mediator Usage
using MoMediatoR;
private readonly IMoMediatoR _moMediatoR;
var result = await _moMediatoR.Send(new GetUserQuery());
await _moMediatoR.Publish(new UserCreatedNotification());
Configuration
- 🚀 Register MediatR in your DI container:
using MoMediatoR;
// Simplified registration
builder.Services.AddMoMediatoR(typeof(Program));
// Or register from specific assemblies
builder.Services.AddMoMediatoR(typeof(MyHandlerClass).Assembly);
| 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 was computed. 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 was computed. 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.
-
net8.0
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.