Shuttle.Core.Mediator 21.0.1-beta

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

In order to get all the relevant bits working you would need to register the IMediator dependency along with all the relevant IParticipant dependencies.

You can register the mediator using IServiceCollection:

services.AddMediator(builder =>
{
    builder.AddParticipants(assembly);
    builder.AddParticipant<Participant>();
    builder.AddParticipant(participantType);
    builder.AddParticipant<Message>(participant);
    builder.AddParticipant(async (T message, CancellationToken cancellationToken) =>
    {
        await Task.CompletedTask.ConfigureAwait(false);
    });
});

Usage

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

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

public class AuditLogParticipant : IParticipant<UserCreated>
{
    public Task ProcessMessageAsync(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.

Participant implementations

public interface IParticipant<in T>
{
    Task ProcessMessageAsync(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.

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.

However, you may wish to make use of one of the existing utility classes:-

RequestMessage<TRequest>

The only expectation from a RequestMessage<TRequest> instance is either a success or failure (along with the failure message).

RequestResponseMessage<TRequest, TResponse>

The RequestResponseMessage<TRequest, TResponse> takes an initial TRequest object and after the mediator processing would expect that there be a TResponse provided using the .WithResponse(TResponse) method. The same success/failure mechanism used in the RequestMessage<TRequest> class is also available on this class.

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 (2)

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

Package Downloads
Shuttle.Access.Application

Application concern implementations such as Shuttle.Core.Mediator participants.

Shuttle.Core.Mediator.OpenTelemetry

OpenTelemetry instrumentation for Shuttle.Core.Mediator implementations.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
21.0.1-beta 29 2/7/2026
21.0.0-alpha 81 1/18/2026
20.0.0 1,017 2/2/2025
14.0.0 1,013 4/30/2024
13.1.1 5,326 12/1/2022
13.0.1 552 9/4/2022
13.0.0 961 5/2/2022
12.0.2 609 4/28/2022
12.0.1 615 4/9/2022
12.0.0 614 3/21/2022
11.0.1 797 6/26/2019
11.0.0 731 6/12/2019