Snowberry.Mediator
1.0.1-alpha
See the version list below for details.
dotnet add package Snowberry.Mediator --version 1.0.1-alpha
NuGet\Install-Package Snowberry.Mediator -Version 1.0.1-alpha
<PackageReference Include="Snowberry.Mediator" Version="1.0.1-alpha" />
<PackageVersion Include="Snowberry.Mediator" Version="1.0.1-alpha" />
<PackageReference Include="Snowberry.Mediator" />
paket add Snowberry.Mediator --version 1.0.1-alpha
#r "nuget: Snowberry.Mediator, 1.0.1-alpha"
#:package Snowberry.Mediator@1.0.1-alpha
#addin nuget:?package=Snowberry.Mediator&version=1.0.1-alpha&prerelease
#tool nuget:?package=Snowberry.Mediator&version=1.0.1-alpha&prerelease
Lightweight mediator implementation (request/response, streaming requests and notifications) with support for pipeline behaviors and pluggable registration via assembly scanning or explicit type lists.
Use this package to decouple request/response handlers, streaming request handlers and notification handlers from callers, and to add cross-cutting pipeline behaviors.
Usage
Register an IMediator implementation and handlers (either by scanning assemblies or by specifying types) and call into the mediator using the IMediator surface:
- Send a request:
ValueTask<TResponse> SendAsync<TRequest, TResponse>(IRequest<TRequest, TResponse> request, CancellationToken) - Create a stream:
IAsyncEnumerable<TResponse> CreateStreamAsync<TRequest, TResponse>(IStreamRequest<TRequest, TResponse> request, CancellationToken) - Publish a notification:
ValueTask PublishAsync<TNotification>(TNotification notification, CancellationToken)
The mediator resolves handlers from an IServiceProvider (provided at construction) and can execute optional pipeline behavior chains when a global pipeline registry is registered.
Features
- Core contracts and supported types (with generic signatures):
IRequest<TRequest, TResponse>/IRequestHandler<TRequest, TResponse>IStreamRequest<TRequest, TResponse>/IStreamRequestHandler<TRequest, TResponse>INotification/INotificationHandler<TNotification>IPipelineBehavior<TRequest, TResponse>IStreamPipelineBehavior<TRequest, TResponse>
- Assembly scanning helper to discover handlers, pipeline behaviors and notification handlers (
MediatorAssemblyHelper). - Global registries for pipeline and notification handlers used at runtime by
Mediator.
Examples
Below are minimal examples demonstrating common usage patterns.
Microsoft Dependency Injection
The repository contains an integration extension (Snowberry.Mediator.Extensions.DependencyInjection) which exposes AddSnowberryMediator to register the mediator and handlers into an IServiceCollection.
Example: register by scanning the current assembly and enable pipeline/notification scanning:
using System.Reflection;
using Microsoft.Extensions.DependencyInjection;
var services = new ServiceCollection();
services.AddSnowberryMediator(options =>
{
options.Assemblies = new List<Assembly> { Assembly.GetExecutingAssembly() };
options.ScanNotificationHandlers = true;
options.ScanPipelineBehaviors = true;
});
var provider = services.BuildServiceProvider();
var mediator = provider.GetRequiredService<Snowberry.Mediator.Abstractions.IMediator>();
// Send a request (example)
// await mediator.SendAsync(new MyRequest(...));
Example: explicit registration of pipeline behaviors (ordered) and notification handlers (no scanning):
services.AddSnowberryMediator(opts =>
{
opts.Assemblies = new List<Assembly>();
opts.RegisterPipelineBehaviors = true;
opts.PipelineBehaviorTypes = new List<Type>
{
typeof(MyApp.Pipeline.LoggingBehavior<,>),
typeof(MyApp.Pipeline.ValidationBehavior<,>)
};
opts.RegisterNotificationHandlers = true;
opts.NotificationHandlerTypes = new List<Type>
{
typeof(MyApp.Notifications.SomeNotificationHandler)
};
});
Pipeline behavior ordering and priority
Pipeline behaviors are executed in a linked delegate chain. The order in which behaviors are executed matters because each behavior receives a NextPipeline delegate that it must call to continue the chain.
Ordering rules:
- When you explicitly provide
PipelineBehaviorTypes(orStreamPipelineBehaviorTypes), the order of types in the list is preserved and used as the base ordering. - When pipeline behaviors are discovered via scanning, or when combining scanned and explicit lists, the framework can use the
PipelineOverwritePriorityAttributeapplied to behavior types to determine priority. PipelineOverwritePriorityAttributecontains an integerPriorityproperty. Higher values indicate higher priority — behaviors with a higherPriorityvalue are executed earlier in the pipeline chain.
Practical guidance:
- If you need a behavior to run first (for example, logging or diagnostics that should wrap everything), give it a higher
Priority. - If you mix scanned behaviors and an explicit list, set priorities on scanned implementations when their relative position matters, or prefer explicit ordering for predictable placement.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. 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. |
-
net9.0
- Snowberry.Mediator.Abstractions (>= 1.0.1-alpha)
- ZLinq (>= 1.5.2)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on Snowberry.Mediator:
| Package | Downloads |
|---|---|
|
Snowberry.Mediator.DependencyInjection.Shared
A small helper library for supporting multiple Dependency Injection frameworks. |
|
|
Snowberry.Mediator.Extensions.DependencyInjection
Extension for the main package to work with `Microsoft.Extensions.DependencyInjection`. |
|
|
Snowberry.Mediator.DependencyInjection
Extension for the main package to work with `Snowberry.DependencyInjection`. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 1.1.0 | 415 | 1/28/2026 | |
| 1.0.4-alpha | 301 | 11/15/2025 | |
| 1.0.3-alpha | 265 | 11/4/2025 | |
| 1.0.2-alpha | 249 | 10/7/2025 | |
| 1.0.1-alpha | 346 | 9/23/2025 | |
| 1.0.0-alpha | 326 | 9/9/2025 |