rmm-soft.Mediator
1.0.3
dotnet add package rmm-soft.Mediator --version 1.0.3
NuGet\Install-Package rmm-soft.Mediator -Version 1.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="rmm-soft.Mediator" Version="1.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="rmm-soft.Mediator" Version="1.0.3" />
<PackageReference Include="rmm-soft.Mediator" />
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 rmm-soft.Mediator --version 1.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: rmm-soft.Mediator, 1.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 rmm-soft.Mediator@1.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=rmm-soft.Mediator&version=1.0.3
#tool nuget:?package=rmm-soft.Mediator&version=1.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
rmm-soft.Mediator
Lightweight mediator implementation for Clean Architecture in .NET. Supports CQRS, pipeline behaviors, and notifications — with no external dependencies beyond Microsoft.Extensions.
Features
- ✅ CQRS — Commands and Queries with
IRequest<TResponse> - ✅ Pipeline Behaviors — cross-cutting concerns (logging, validation, exception handling)
- ✅ Notifications — publish/subscribe pattern with
INotification - ✅ Notification Behaviors — pipeline for notifications
- ✅ Zero magic — explicit, readable, no reflection tricks
- ✅ DI friendly — works with
Microsoft.Extensions.DependencyInjection
Installation
dotnet add package rmm-soft.Mediator
Quick Start
1. Register in DI
// Program.cs
builder.Services.AddRmmSoftMediator(Assembly.GetExecutingAssembly());
// Register your pipeline behaviors (in order)
builder.Services.AddTransient(typeof(IPipelineBehavior<,>), typeof(LoggingBehavior<,>));
builder.Services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ValidationBehavior<,>));
2. Define a Command
public record CreateProductCommand : IRequest<int>
{
public string Name { get; set; } = string.Empty;
public decimal Price { get; set; }
}
3. Implement the Handler
public record CreateProductCommandHandler(
IProductRepository repository) : IRequestHandler<CreateProductCommand, int>
{
public async Task<int> Handle(CreateProductCommand request, CancellationToken cancellationToken)
{
var product = new Product { Name = request.Name, Price = request.Price };
await repository.AddAsync(product);
return product.Id;
}
}
4. Send the Command
public class ProductController(IAppMediator mediator) : ControllerBase
{
[HttpPost]
public async Task<IActionResult> Create([FromBody] CreateProductCommand command)
{
var id = await mediator.Send<CreateProductCommand, int>(command);
return CreatedAtAction(nameof(GetById), new { id }, null);
}
}
Pipeline Behaviors
Pipeline behaviors allow you to add cross-cutting concerns to all commands and queries.
public class LoggingBehavior<TRequest, TResponse>(ILogger<LoggingBehavior<TRequest, TResponse>> logger)
: IPipelineBehavior<TRequest, TResponse>
{
public async Task<TResponse> Handle(
TRequest request,
Func<Task<TResponse>> next,
CancellationToken cancellationToken)
{
logger.LogInformation("Handling {RequestType}", typeof(TRequest).Name);
var response = await next();
logger.LogInformation("Handled {RequestType}", typeof(TRequest).Name);
return response;
}
}
Notifications
Use notifications for domain events and pub/sub patterns.
// Define notification
public record OrderCreatedNotification(int OrderId, string UserId) : INotification;
// Implement handler
public class SendEmailOnOrderCreated : INotificationHandler<OrderCreatedNotification>
{
public async Task Handle(OrderCreatedNotification notification, CancellationToken cancellationToken)
{
// send email...
}
}
// Publish
await mediator.Publish(new OrderCreatedNotification(order.Id, userId));
Void Commands (no return value)
// Command with no response
public record DeleteProductCommand(int Id) : IRequest;
// Handler
public record DeleteProductCommandHandler(IProductRepository repository)
: IRequestHandler<DeleteProductCommand>
{
public async Task Handle(DeleteProductCommand request, CancellationToken cancellationToken)
{
await repository.DeleteAsync(request.Id);
}
}
// Send
await mediator.Send(new DeleteProductCommand(id));
DI Registration Options
// Register handlers from multiple assemblies
services.AddRmmSoftMediator(
Assembly.GetExecutingAssembly(),
typeof(SomeOtherHandler).Assembly
);
License
MIT — see LICENSE 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- Microsoft.Extensions.DependencyInjection (>= 10.0.5)
- Microsoft.Extensions.Logging (>= 10.0.5)
- Scrutor (>= 7.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.