SimpleMediatorLib 1.0.2
dotnet add package SimpleMediatorLib --version 1.0.2
NuGet\Install-Package SimpleMediatorLib -Version 1.0.2
<PackageReference Include="SimpleMediatorLib" Version="1.0.2" />
<PackageVersion Include="SimpleMediatorLib" Version="1.0.2" />
<PackageReference Include="SimpleMediatorLib" />
paket add SimpleMediatorLib --version 1.0.2
#r "nuget: SimpleMediatorLib, 1.0.2"
#:package SimpleMediatorLib@1.0.2
#addin nuget:?package=SimpleMediatorLib&version=1.0.2
#tool nuget:?package=SimpleMediatorLib&version=1.0.2
SimpleMediator
A simple, lightweight mediator pattern implementation for .NET with support for request/response handlers, notifications, and pipeline behaviors.
Installation
dotnet add package SimpleMediatorLib
Supported Frameworks
SimpleMediator supports a wide range of .NET implementations, including all future versions:
- .NET Standard 2.0 - Compatible with .NET Framework 4.6.1+, .NET Core 2.0+
- .NET Standard 2.1 - Compatible with .NET Core 2.1+, .NET 5+, .NET 6+, .NET 7+, .NET 8+, and all future .NET versions
By targeting .NET Standard, SimpleMediator automatically works with all current and future .NET implementations without requiring package updates.
Quick Start
1. Register SimpleMediator
using SimpleMediator;
using System.Reflection;
builder.Services.AddSimpleMediator(
typeof(YourApplicationAssemblyMarker).Assembly
);
2. Create a Request
public sealed record GetUserQuery(int UserId)
: IRequest<User>;
public sealed class GetUserQueryHandler
: IRequestHandler<GetUserQuery, User>
{
public Task<User> Handle(
GetUserQuery request,
CancellationToken cancellationToken)
{
// Your logic here
return Task.FromResult(new User { Id = request.UserId });
}
}
3. Send a Request
public class UserController : ControllerBase
{
private readonly IMediator _mediator;
public UserController(IMediator mediator)
{
_mediator = mediator;
}
[HttpGet("{id}")]
public async Task<ActionResult<User>> GetUser(int id)
{
var user = await _mediator.Send(new GetUserQuery(id));
return Ok(user);
}
}
Features
- Request/Response Pattern: Send requests and receive typed responses
- Notifications: Publish notifications to multiple handlers
- Pipeline Behaviors: Add cross-cutting concerns (logging, validation, etc.)
- Dependency Injection: Seamless integration with Microsoft.Extensions.DependencyInjection
- Assembly Scanning: Automatically discovers and registers handlers
Pipeline Behaviors
Add cross-cutting concerns using pipeline behaviors:
public class LoggingBehavior<TRequest, TResponse>
: IPipelineBehavior<TRequest, TResponse>
where TRequest : IRequest<TResponse>
{
private readonly ILogger<LoggingBehavior<TRequest, TResponse>> _logger;
public LoggingBehavior(ILogger<LoggingBehavior<TRequest, TResponse>> logger)
{
_logger = logger;
}
public async Task<TResponse> Handle(
TRequest request,
CancellationToken cancellationToken,
RequestHandlerDelegate<TResponse> next)
{
_logger.LogInformation("Handling {RequestType}", typeof(TRequest).Name);
var response = await next();
_logger.LogInformation("Handled {RequestType}", typeof(TRequest).Name);
return response;
}
}
Notifications
Publish notifications to multiple handlers:
public sealed record UserCreatedEvent(int UserId, string UserName)
: INotification;
public sealed class SendWelcomeEmailHandler
: INotificationHandler<UserCreatedEvent>
{
public Task Handle(UserCreatedEvent notification, CancellationToken cancellationToken)
{
// Send welcome email
return Task.CompletedTask;
}
}
public sealed class UpdateUserCacheHandler
: INotificationHandler<UserCreatedEvent>
{
public Task Handle(UserCreatedEvent notification, CancellationToken cancellationToken)
{
// Update cache
return Task.CompletedTask;
}
}
// Publish the notification
await _mediator.Publish(new UserCreatedEvent(userId, userName));
License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.CSharp (>= 4.7.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0.0)
-
.NETStandard 2.1
- Microsoft.CSharp (>= 4.7.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on SimpleMediatorLib:
| Package | Downloads |
|---|---|
|
Application.Abstraction
CQRS abstractions for .NET application layers using SimpleMediator and Core.Result. |
GitHub repositories
This package is not used by any popular GitHub repositories.