Shuttle.Mediator 21.0.1

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

Shuttle.Core.Mediator

The Shuttle.Core.Mediator package provides a mediator pattern implementation.

Installation

dotnet add package Shuttle.Core.Mediator

Configuration

Register the IMediator dependency along with all the relevant IParticipant dependencies.

You can register the mediator using IServiceCollection:

services.AddMediator(options =>
{
    options.Sending += async (sender, args) => await Task.CompletedTask;
}).AddParticipantsFrom(assembly);

The AddMediator method returns a MediatorBuilder that can be used to further configure the mediator:

services.AddMediator()
    .AddParticipantsFrom(assembly)
    .AddParticipantsFrom(new[] { assembly1, assembly2 })
    .AddParticipant<Participant>()
    .AddParticipant(participantType)
    
    // The default service lifetime, Scoped, can be explicitly overidden:
    .AddParticipant(participantType, _ => ServiceLifetime.Transient)
    
    // Instance registration
    .AddParticipant(participant)
    
    // Delegate registration
    .AddParticipant(async (UserCreated message, CancellationToken cancellationToken) =>
    {
        await Task.CompletedTask;
    })

    // Delegate registration with dependency injection
    .AddParticipant(async (UserCreated message, IService service, CancellationToken cancellationToken) =>
    {
        await service.DoSomethingAsync(message);
    });

Usage

// Define a message
public class UserCreated
{
    public string UserName { get; set; }
}

// Create participants
public class EmailNotificationParticipant : IParticipant<UserCreated>
{
    public Task HandleAsync(UserCreated message, CancellationToken cancellationToken = default)
    {
        Console.WriteLine($"Sending welcome email to {message.UserName}");
        return Task.CompletedTask;
    }
}

public class AuditLogParticipant : IParticipant<UserCreated>
{
    public Task HandleAsync(UserCreated message, CancellationToken cancellationToken = default)
    {
        Console.WriteLine($"Auditing user creation: {message.UserName}");
        return Task.CompletedTask;
    }
}

// Send the message
await mediator.SendAsync(new UserCreated { UserName = "john.doe" });

IMediator

The core interface is the IMediator interface and the default implementation provided is the Mediator class.

Participants types are instantiated from the IServiceProvider instance. This means that it depends on how you register the type as to the behavior.

Task SendAsync(object message, CancellationToken cancellationToken = default);

The SendAsync method will find all participants that implement the IParticipant<T> with the type T of the message type that you are sending.

IParticipant implementations

public interface IParticipant<in T>
{
    Task HandleAsync(T message, CancellationToken cancellationToken = default);
}

A participant would handle the message that is sent using the mediator. There may be any number of participants that process the message, but there must be at least one participant or delegate registered for the message type.

Design philosophy

There are no request/response semantics and the design philosophy here is that the message encapsulates the state that is passed along in a pipes & filters approach.

MediatorOptions

The MediatorOptions class provides the following events:

  • Sending: An AsyncEvent<SendEventArgs> that is raised before a message is sent to participants.
  • Sent: An AsyncEvent<SendEventArgs> that is raised after a message has been sent to all participants.

Considerations

If you have a rather predictable sequential workflow and you require something with faster execution then you may wish to consider the Shuttle.Core.Pipelines package.

Performing a benchmark for your use-case would be able to indicate the more suitable option.

Product 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.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Shuttle.Mediator:

Package Downloads
Shuttle.Access.Application

Application concern implementations such as Shuttle.Mediator participants.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
21.0.1 64 4/15/2026
21.0.1-rc3 68 4/11/2026