Snowberry.Mediator
1.1.0
dotnet add package Snowberry.Mediator --version 1.1.0
NuGet\Install-Package Snowberry.Mediator -Version 1.1.0
<PackageReference Include="Snowberry.Mediator" Version="1.1.0" />
<PackageVersion Include="Snowberry.Mediator" Version="1.1.0" />
<PackageReference Include="Snowberry.Mediator" />
paket add Snowberry.Mediator --version 1.1.0
#r "nuget: Snowberry.Mediator, 1.1.0"
#:package Snowberry.Mediator@1.1.0
#addin nuget:?package=Snowberry.Mediator&version=1.1.0
#tool nuget:?package=Snowberry.Mediator&version=1.1.0
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 | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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 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 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Snowberry.Mediator.Abstractions (>= 1.1.0)
- ZLinq (>= 1.5.4)
-
net10.0
- Snowberry.Mediator.Abstractions (>= 1.1.0)
- ZLinq (>= 1.5.4)
-
net9.0
- Snowberry.Mediator.Abstractions (>= 1.1.0)
- ZLinq (>= 1.5.4)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on Snowberry.Mediator:
| Package | Downloads |
|---|---|
|
Snowberry.Mediator.Extensions.DependencyInjection
Extension for the main package to work with `Microsoft.Extensions.DependencyInjection`. |
|
|
Snowberry.Mediator.DependencyInjection.Shared
A small helper library for supporting multiple Dependency Injection frameworks. |
|
|
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 | 85 | 1/28/2026 | |
| 1.0.4-alpha | 187 | 11/15/2025 | |
| 1.0.3-alpha | 174 | 11/4/2025 | |
| 1.0.2-alpha | 163 | 10/7/2025 | |
| 1.0.1-alpha | 261 | 9/23/2025 | |
| 1.0.0-alpha | 257 | 9/9/2025 |