Nast.SimpleMediator
1.1.0
dotnet add package Nast.SimpleMediator --version 1.1.0
NuGet\Install-Package Nast.SimpleMediator -Version 1.1.0
<PackageReference Include="Nast.SimpleMediator" Version="1.1.0" />
<PackageVersion Include="Nast.SimpleMediator" Version="1.1.0" />
<PackageReference Include="Nast.SimpleMediator" />
paket add Nast.SimpleMediator --version 1.1.0
#r "nuget: Nast.SimpleMediator, 1.1.0"
#:package Nast.SimpleMediator@1.1.0
#addin nuget:?package=Nast.SimpleMediator&version=1.1.0
#tool nuget:?package=Nast.SimpleMediator&version=1.1.0
SimpleMediator
A lightweight and efficient implementation of the Mediator pattern for .NET applications.
Support policy: ships a single net8.0 asset validated for .NET 8, .NET 9, and .NET 10.
Features
- Request/response handling with typed results
- Notifications with multiple handlers
- Async stream requests via
IAsyncEnumerable<T> - Dependency-injection integration for Microsoft.Extensions.DependencyInjection
- Explicit handler registration for deterministic startup
- Real pipeline behaviors through
IPipelineBehavior<TRequest, TResponse>
Installation
dotnet add package Nast.SimpleMediator
Runtime Support
Validated support matrix: .NET 8, .NET 9, and .NET 10.
SimpleMediator publishes a single net8.0 package asset. Consumers on .NET 8/9/10 use that same asset, and release validation proves the package metadata, runtime matrix, and package contents stay aligned.
Registration
AddMediator() only registers the mediator core services. To discover handlers, pass the assemblies you want scanned explicitly.
using Nast.SimpleMediator;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddMediator(typeof(Program).Assembly);
builder.Services.AddMediator(options =>
{
options.RegisterServicesFromAssemblies(typeof(Program).Assembly);
options.AddBehavior<LoggingBehavior>();
});
Requests and Responses
public record GetUserQuery(int UserId) : IRequest<User>;
public sealed class GetUserHandler : IRequestHandler<GetUserQuery, User>
{
private readonly IUserRepository _repository;
public GetUserHandler(IUserRepository repository)
{
_repository = repository;
}
public Task<User> Handle(GetUserQuery request, CancellationToken cancellationToken)
{
return _repository.GetByIdAsync(request.UserId);
}
}
Notifications
public record UserCreatedNotification(int UserId, string Email) : INotification;
public sealed class EmailNotificationHandler : INotificationHandler<UserCreatedNotification>
{
private readonly IEmailService _emailService;
public EmailNotificationHandler(IEmailService emailService)
{
_emailService = emailService;
}
public Task Handle(UserCreatedNotification notification, CancellationToken cancellationToken)
{
return _emailService.SendWelcomeEmailAsync(notification.Email);
}
}
Custom Pipeline Behaviors
Custom behaviors MUST implement IPipelineBehavior<TRequest, TResponse>.
public sealed class LoggingBehavior : IPipelineBehavior<GetUserQuery, User>
{
private readonly ILogger<LoggingBehavior> _logger;
public LoggingBehavior(ILogger<LoggingBehavior> logger)
{
_logger = logger;
}
public async Task<User> Handle(
GetUserQuery request,
RequestHandlerDelegate<User> next,
CancellationToken cancellationToken)
{
_logger.LogInformation("Handling {RequestType}", typeof(GetUserQuery).Name);
var response = await next();
_logger.LogInformation("Handled {RequestType}", typeof(GetUserQuery).Name);
return response;
}
}
This keeps the behavior contract honest: the mediator resolves and executes IPipelineBehavior<TRequest, TResponse> instances in registration order around the real handler.
Breaking Changes in 1.1
- Consumers that relied on ambient loaded-assembly scanning must switch to explicit assembly registration.
- Legacy behavior abstractions that do not implement
IPipelineBehavior<TRequest, TResponse>are no longer supported. AddMediator()without assemblies is still valid, but it now registers only the mediator core services.
Migration Checklist
- Replace no-argument registration used for handler discovery with
AddMediator(typeof(Program).Assembly)orRegisterServicesFromAssemblies(...). - Replace custom behavior interfaces with concrete
IPipelineBehavior<TRequest, TResponse>implementations. - Keep package/runtime expectations aligned with the validated support matrix: .NET 8, .NET 9, and .NET 10.
License
This project is licensed under the MIT License. See LICENSE for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. 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. |
-
net8.0
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Support policy: ships a single net8.0 asset validated for .NET 8, .NET 9, and .NET 10.