GM.Mediator
1.3.2
See the version list below for details.
dotnet add package GM.Mediator --version 1.3.2
NuGet\Install-Package GM.Mediator -Version 1.3.2
<PackageReference Include="GM.Mediator" Version="1.3.2" />
<PackageVersion Include="GM.Mediator" Version="1.3.2" />
<PackageReference Include="GM.Mediator" />
paket add GM.Mediator --version 1.3.2
#r "nuget: GM.Mediator, 1.3.2"
#:package GM.Mediator@1.3.2
#addin nuget:?package=GM.Mediator&version=1.3.2
#tool nuget:?package=GM.Mediator&version=1.3.2
GM.Mediator
A lightweight, dependency-injection-friendly mediator for .NET — send requests, publish
notifications, and wrap handlers in pipeline behaviors, with no external dependencies
beyond Microsoft.Extensions.DependencyInjection.Abstractions.
Targets net10.0.
Install
dotnet add package GM.Mediator
Register
Scan one or more assemblies for handlers and behaviors:
using GM.Mediator;
services.AddGMMediator(typeof(Program).Assembly);
// Optional: choose the service lifetime (defaults to Scoped)
services.AddGMMediator(ServiceLifetime.Transient, typeof(Program).Assembly);
Requests with a response
public record GetUser(int Id) : IRequest<UserDto>;
public class GetUserHandler : IRequestHandler<GetUser, UserDto>
{
public Task<UserDto> Handle(GetUser request, CancellationToken ct) => /* ... */;
}
// usage
UserDto user = await mediator.Send(new GetUser(42));
Requests without a response
public record DeleteUser(int Id) : IRequest;
public class DeleteUserHandler : IRequestHandler<DeleteUser>
{
public Task Handle(DeleteUser request, CancellationToken ct) => /* ... */;
}
await mediator.Send(new DeleteUser(42));
Notifications (multiple handlers)
public record UserCreated(int Id) : INotification;
public class SendWelcomeEmail : INotificationHandler<UserCreated> { /* ... */ }
public class UpdateAnalytics : INotificationHandler<UserCreated> { /* ... */ }
await mediator.Publish(new UserCreated(42)); // both handlers run
Pipeline behaviors
Behaviors wrap handlers and run in registration order (first registered = outermost). Both response and no-response variants are supported.
public class LoggingBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
{
public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next, CancellationToken ct)
{
// before
var response = await next();
// after
return response;
}
}
Open generic behaviors are registered automatically by AddGMMediator.
License
MIT — see LICENSE.
| 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
NuGet packages (4)
Showing the top 4 NuGet packages that depend on GM.Mediator:
| Package | Downloads |
|---|---|
|
GM.API.Application
Application-layer building blocks for the GM.API stack: GM.Mediator wiring plus validation and performance pipeline behaviours, and paged-list models. Part of the GM.API family. |
|
|
GM.FeatureManagement.Mediator
GM.Mediator integration for GM.FeatureManagement: a pipeline behavior that gates command/query handlers behind a feature flag. Mark a request with IFeatureGatedRequest or [FeatureGate("Key")] and the handler runs only when the flag is enabled for the ambient FeatureContext; otherwise a FeatureDisabledException short-circuits the pipeline before the handler. Register with AddGMFeatureGateBehavior(). |
|
|
GM.Idempotency.Mediator
GM.Mediator integration for GM.Idempotency: IdempotencyBehavior<TRequest, TResponse>, a pipeline behavior that dedups a request/command before the handler runs — keyed by an explicit id (IIdempotentRequest, e.g. a RabbitMQ message id) or a hash of the payload ([Idempotent]) — via the distributed-lock-guarded check-and-set, and replays the stored response on redelivery. For exactly-once handling of at-least-once message delivery (GM.Messaging). Register with AddGMIdempotencyBehavior(). |
|
|
GM.Testing.Mediator
GM.Mediator test helpers. Invoke a command/query handler directly in a unit test, bypassing the whole pipeline (InvokeHandlerAsync), or run through the real mediator with pipeline behaviors selectively removed (RemovePipelineBehaviors / RemovePipelineBehavior(typeof(SomeBehavior<,>))) — so unit tests skip idempotency/validation/logging behaviors while integration tests keep them. Test-only (DevelopmentDependency). |
GitHub repositories
This package is not used by any popular GitHub repositories.