MediatorLite.Abstractions
1.0.13
dotnet add package MediatorLite.Abstractions --version 1.0.13
NuGet\Install-Package MediatorLite.Abstractions -Version 1.0.13
<PackageReference Include="MediatorLite.Abstractions" Version="1.0.13" />
<PackageVersion Include="MediatorLite.Abstractions" Version="1.0.13" />
<PackageReference Include="MediatorLite.Abstractions" />
paket add MediatorLite.Abstractions --version 1.0.13
#r "nuget: MediatorLite.Abstractions, 1.0.13"
#:package MediatorLite.Abstractions@1.0.13
#addin nuget:?package=MediatorLite.Abstractions&version=1.0.13
#tool nuget:?package=MediatorLite.Abstractions&version=1.0.13
MediatorLite
A lightweight, high-performance mediator library for .NET 10+. Built from the ground up with source generators for zero-reflection dispatch and minimal allocations.
Documentation: behl1anmol.github.io/MediatorLite
Features
- High Performance - Source generators eliminate runtime reflection for handler dispatch
- Zero-Reflection Dispatch - Compile-time handler discovery and typed dispatch via source generation
- Lightweight - Minimal dependencies, focused core
- Extensible - Pipeline behaviors for cross-cutting concerns
- Request/Response - Type-safe command and query handling with
ValueTask - Notifications - Pub-sub pattern with sequential, parallel, and stop-on-first strategies
- Observable - Built-in logging and OpenTelemetry tracing support
- DI Native - First-class
Microsoft.Extensions.DependencyInjectionintegration
Installation
dotnet add package MediatorLite
Optional (contracts-only scenarios such as shared request assemblies):
dotnet add package MediatorLite.Abstractions
Package and Versioning Guide
Which package should I install?
| Project Type | Install | Why |
|---|---|---|
| Application/API that sends requests | MediatorLite + MediatorLite.SourceGeneration |
Full runtime + compile-time handler discovery |
| Application/API without source generation | MediatorLite |
Full runtime, reflection fallback still works |
| Shared contracts library (requests/notifications only) | MediatorLite.Abstractions |
Keep shared package lightweight |
Will Abstractions be installed automatically?
- If you install
MediatorLite, yes.MediatorLite.Abstractionsis pulled transitively. - If you install only
MediatorLite.SourceGeneration, no. Source generation package does not pull runtime contracts by itself. - If you install both
MediatorLiteandMediatorLite.SourceGeneration, yes (viaMediatorLite).
Compatibility Matrix
Use this matrix as the default rule for safe upgrades.
| MediatorLite.Abstractions | MediatorLite | MediatorLite.SourceGeneration | Supported | Notes |
|---|---|---|---|---|
| 1.0.x | 1.0.x | 1.0.x | Yes | Recommended lockstep |
| (transitive) | 1.0.x | 1.0.x | Yes | Typical app setup; Abstractions arrives via MediatorLite |
| 1.0.x | 1.0.x | not installed | Yes | Runtime works without source generation |
| 1.0.x | not installed | 1.0.x | No | Missing runtime package for mediator usage |
| 1.0.x | 2.0.x | 2.0.x | No | Cross-major mismatch with MediatorLite |
| 2.0.x | 2.0.x | 1.0.x | No | Source generator major mismatch |
| 1.1.x | 1.0.x | 1.0.x | Caution | May compile, but not a tested combination |
Versioning Policy
MediatorLite.Abstractionsfollows strict SemVer:- Patch: docs/internal fixes, no API break
- Minor: additive API only, backward compatible
- Major: breaking contract changes
MediatorLitedeclares a dependency onMediatorLite.Abstractions.- For predictable restores, keep all three packages on the same major and minor version.
- For pre-release builds, use matching pre-release versions across packages (for example, all
1.2.0-preview.3).
Upgrade Checklist
- Upgrade
MediatorLitefirst. - Upgrade
MediatorLite.SourceGenerationto the same major/minor. - If you directly reference
MediatorLite.Abstractions, align it to the same major/minor. - Run
dotnet restoreanddotnet buildto force source regeneration and verify compatibility.
Quick Start
1. Define a Request and Handler
public record GetUserQuery(int Id) : IRequest<User>;
public class GetUserQueryHandler : IRequestHandler<GetUserQuery, User>
{
public ValueTask<User> HandleAsync(GetUserQuery request, CancellationToken cancellationToken = default)
{
return ValueTask.FromResult(new User(request.Id, "John Doe"));
}
}
2. Register Services
The source generator automatically discovers all handlers at compile time. Use AddGeneratedHandlers() to register them with the DI container:
using MediatorLite.Generated;
services
.AddGeneratedHandlers() // Source-generated: registers all handlers, notifications, behaviors
.AddMediatorLite(); // Registers the mediator and options
AddGeneratedHandlers() registers:
- All
IRequestHandler<,>implementations - All
INotificationHandler<>implementations - All
IPipelineBehavior<,>implementations - The
ISourceGeneratedMediatorfor zero-reflection dispatch
To configure options:
services
.AddGeneratedHandlers()
.AddMediatorLite(options =>
{
options.EnableBuiltInLogging = true;
options.EnableTracing = true;
options.NotificationExecutionStrategy = NotificationExecutionStrategy.Parallel;
});
Granular Registration
If you only need to register specific handler categories:
services
.AddGeneratedRequestHandlers() // Only request handlers
.AddGeneratedNotificationHandlers() // Only notification handlers
.AddGeneratedBehaviors() // Only pipeline behaviors
.AddMediatorLite();
Manual DI Registration (Without Source Generation)
You can register handlers manually with standard DI if preferred:
services.AddTransient<IRequestHandler<GetUserQuery, User>, GetUserQueryHandler>();
services.AddTransient<INotificationHandler<UserCreatedNotification>, SendWelcomeEmailHandler>();
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(LoggingBehavior<,>));
services.AddMediatorLite();
Excluding Types from Source Generation
Use [MediatorGeneration(Skip = true)] to exclude specific handlers from source-generated discovery:
[MediatorGeneration(Skip = true)]
public class TestOnlyHandler : IRequestHandler<TestQuery, string>
{
// This handler will NOT be registered by AddGeneratedHandlers()
}
3. Send Requests
public class MyService(IMediator mediator)
{
public async Task<User> GetUserAsync(int id, CancellationToken ct)
{
return await mediator.SendAsync(new GetUserQuery(id), ct);
}
}
4. Publish Notifications
public record UserCreatedNotification(int UserId, string Email) : INotification;
// Multiple handlers can subscribe
public class SendWelcomeEmailHandler : INotificationHandler<UserCreatedNotification>
{
public async ValueTask HandleAsync(UserCreatedNotification notification, CancellationToken ct = default)
{
await _emailService.SendWelcomeAsync(notification.Email);
}
}
// Publish
await mediator.PublishAsync(new UserCreatedNotification(user.Id, user.Email));
Documentation
Full documentation is available at behl1anmol.github.io/MediatorLite.
Notification Execution Strategies
MediatorLite provides flexible notification execution with three strategies:
| Strategy | Description | Error Handling |
|---|---|---|
| Sequential | Handlers run one-by-one in order | Error strategy applies |
| Parallel | All handlers run concurrently | Always aggregates exceptions* |
| StopOnFirst | Stops after first successful handler | Error strategy applies |
*Parallel mode always aggregates exceptions because concurrent tasks cannot be cancelled mid-execution.
services.AddMediatorLite(options =>
{
options.NotificationExecutionStrategy = NotificationExecutionStrategy.Parallel;
options.NotificationErrorStrategy = NotificationErrorStrategy.ContinueAndAggregate;
});
See Notifications documentation for detailed strategy behavior and error handling patterns.
Why MediatorLite?
| Feature | MediatorLite | MediatR |
|---|---|---|
| Handler Discovery | Compile-time (source gen) | Runtime reflection |
| Handler Dispatch | Zero-reflection typed dispatch | Reflection-based |
| ValueTask Support | Native | Task only |
| OpenTelemetry | Built-in | Manual |
| Notification Strategies | Sequential, Parallel, StopOnFirst | Sequential only |
| License | MIT | Commercial |
License
This project is licensed under the MIT License - see the LICENSE file for details.
| Product | Versions 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. |
-
net10.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on MediatorLite.Abstractions:
| Package | Downloads |
|---|---|
|
MediatorLite
A lightweight, high-performance mediator library for .NET. Features source generators for zero-reflection handler discovery, pipeline behaviors, and built-in observability. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.13 | 98 | 3/30/2026 |