GM.Mediator 1.3.3

dotnet add package GM.Mediator --version 1.3.3
                    
NuGet\Install-Package GM.Mediator -Version 1.3.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="GM.Mediator" Version="1.3.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="GM.Mediator" Version="1.3.3" />
                    
Directory.Packages.props
<PackageReference Include="GM.Mediator" />
                    
Project file
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 GM.Mediator --version 1.3.3
                    
#r "nuget: GM.Mediator, 1.3.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 GM.Mediator@1.3.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=GM.Mediator&version=1.3.3
                    
Install as a Cake Addin
#tool nuget:?package=GM.Mediator&version=1.3.3
                    
Install as a Cake Tool

<p align="center"> <img src="https://raw.githubusercontent.com/gmetskhvarishvili/GM.Mediator/master/icon.png" alt="GM.Mediator" width="140" height="140" /> </p>

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.

Version Downloads Last Updated
1.3.3 138 7/30/2026
1.3.2 136 7/27/2026
1.3.1 104 7/27/2026
1.2.0 301 1/6/2026
1.1.0 264 5/18/2025
1.0.1 239 5/4/2025
1.0.0 217 4/28/2025