Fusonic.Extensions.Mediator 11.0.0

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

Mediator

Package: Fusonic.Extensions.Mediator (namespace Fusonic.Extensions.Mediator)

A simple implementation of the mediator pattern, based on version 11.1.0 of the MediatR package. The pipelining was removed; use the decorators of your DI container instead.

  • ICommand/ICommand<TResponse>, IQuery<TResponse>: use these instead of IRequest to distinguish commands from queries.
  • INotification: published to all its INotificationHandler<T>.
  • IAsyncEnumerableRequest<T>: streamed via IAsyncEnumerableRequestHandler<TRequest, T> and IMediator.CreateAsyncEnumerable.
  • OutOfBandAttribute: put it on a handler class to run it as a background job, together with the out-of-band decorators of Fusonic.Extensions.Hangfire. Only applies to handlers without a response (Unit) and to notification handlers.

Usage

using Fusonic.Extensions.Mediator;

public record CreateUser(string Name) : ICommand<int>;

public class CreateUserHandler : IRequestHandler<CreateUser, int>
{
    public Task<int> Handle(CreateUser request, CancellationToken cancellationToken) => ...;
}

public record UserCreated(int Id) : INotification;

public class UserCreatedHandler : INotificationHandler<UserCreated>
{
    public Task Handle(UserCreated notification, CancellationToken cancellationToken) => ...;
}

// Inject IMediator (ISender and IPublisher are not registered)
var id = await mediator.Send(new CreateUser("Jane"));
await mediator.Publish(new UserCreated(id));

For commands without a response, implement IRequestHandler<TRequest> (returns Task<Unit>) or derive from AsyncRequestHandler<TRequest> (returns Task).

Registration with SimpleInjector

The package references SimpleInjector with PrivateAssets="all", so your project must reference SimpleInjector itself.

using Fusonic.Extensions.Mediator;

container.RegisterMediator(services, [typeof(Program).Assembly]);

RegisterMediator scans the given assemblies and registers all request, notification and async enumerable handlers as scoped, and IMediator as singleton. It also registers IMediator in the given IServiceCollection (resolved from the container), so it can be injected into services of the Microsoft DI container.

When using the out-of-band decorators of Fusonic.Extensions.Hangfire, call container.RegisterOutOfBandDecorators() before RegisterMediator.

Transaction handling

By default RegisterMediator decorates all request and notification handlers with TransactionalRequestHandlerDecorator<,> and TransactionalNotificationHandlerDecorator<>, so they run within a TransactionScope. It also registers ITransactionScopeHandler (from Fusonic.Extensions.Common.Transactions). To disable this:

container.RegisterMediator(services, [typeof(Program).Assembly], o => o.EnableTransactionalDecorators = false);

Custom IMediator implementation

RegisterMediator registers a ServiceProviderMediator resolving the handlers from the container. To use your own implementation:

container.Options.AllowOverridingRegistrations = true;
container.RegisterSingleton<IMediator, MyCustomMediator>();

Registration with Microsoft.Extensions.DependencyInjection and Scrutor

There is no registration helper for Microsoft DI. Register the mediator and the handlers yourself, e.g. with Scrutor (referenced by your project). Unlike with SimpleInjector, the transactional decorators are opt-in.

using Fusonic.Extensions.Common.Transactions;
using Fusonic.Extensions.Mediator;
using Fusonic.Extensions.Mediator.DependencyInjection;

services.AddTransient<IMediator>(sp => new ServiceProviderMediator(sp));

services.Scan(s => s.FromAssemblyOf<Program>()
        .AddClasses(c => c.AssignableToAny(typeof(IRequestHandler<,>), typeof(INotificationHandler<>), typeof(IAsyncEnumerableRequestHandler<,>)))
        .AsImplementedInterfaces()
        .WithScopedLifetime());

// When using Fusonic.Extensions.Hangfire: services.AddOutOfBandDecorators() must be called here, before any other handler decorator.

// Optional: Run all requests and notifications within a TransactionScope
services.TryDecorate(typeof(IRequestHandler<,>), typeof(TransactionalRequestHandlerDecorator<,>));
services.TryDecorate(typeof(INotificationHandler<>), typeof(TransactionalNotificationHandlerDecorator<>));
services.AddSingleton<ITransactionScopeHandler, TransactionScopeHandler>();

Scrutor only decorates services registered before the Decorate/TryDecorate call, so register the handlers first.

Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on Fusonic.Extensions.Mediator:

Package Downloads
Fusonic.Extensions.Hangfire

Provides Hangfire extensions, especially suited for CQRS development. (Out of band processing).

Fusonic.Extensions.AspNetCore

Provides ASP.NET Core extensions (Middelwares, Utilities ...)

Fusonic.Extensions.Email

Contains common functionality for rendering email templates using razor engine and sending emails via MailKit.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
11.0.0 0 11/23/2026
10.3.0 482 11/9/2026
10.2.0 335 11/5/2026
10.1.0 6,457 3/18/2026
10.0.1 161 3/17/2026
10.0.0 1,329 11/25/2025
10.0.0-rc.2 201 11/24/2025
10.0.0-rc.1 178 9/12/2025
9.5.4 714 8/20/2025
9.5.3 713 3/28/2025
9.5.2 845 1/16/2025
9.5.0 398 10/4/2024
9.4.0 458 9/23/2024
9.3.1 408 9/11/2024
9.3.0 294 9/11/2024
9.2.0 305 8/8/2024
9.2.0-rc.3 142 8/7/2024
9.2.0-rc.2 116 8/5/2024
9.2.0-rc.1 138 8/1/2024
9.1.0 255 7/29/2024
Loading failed