Shuttle.Core.Mediator
13.0.0
Prefix Reserved
See the version list below for details.
dotnet add package Shuttle.Core.Mediator --version 13.0.0
NuGet\Install-Package Shuttle.Core.Mediator -Version 13.0.0
<PackageReference Include="Shuttle.Core.Mediator" Version="13.0.0" />
paket add Shuttle.Core.Mediator --version 13.0.0
#r "nuget: Shuttle.Core.Mediator, 13.0.0"
// Install Shuttle.Core.Mediator as a Cake Addin #addin nuget:?package=Shuttle.Core.Mediator&version=13.0.0 // Install Shuttle.Core.Mediator as a Cake Tool #tool nuget:?package=Shuttle.Core.Mediator&version=13.0.0
Shuttle.Core.Mediator
PM> Install-Package Shuttle.Core.Mediator
The Shuttle.Core.Mediator package provides a mediator pattern implementation.
IMediator
The core interface is the IMediator
interface and the default implementation provided is the Mediator
class.
This interface provides a synchronous calling mechanism and all IParticipant
implementations need to be thread-safe singleton implementations that are added to the mediator at startup. Any operations that require transient mechanisms should be handled by the relevant participant.
IMediator Add(object participant);
The Add
method registers the given participant.
void Send(object message, CancellationToken cancellationToken = default);
The Send
method will find all participants that implements the IParticipant<T>
with the type T
of the message type that you are sending. Participants that are marked with the BeforeObserverAttribute
filter will be executed first followed by all participants with no filters attributes and then finally all participants marked with the AfterObserverAttribute
filter will be called.
Extensions
Task SendAsync(this IMediator mediator, object message, CancellationToken cancellationToken = default)
Sends a message asynchronously.
public static T Send<T>(this IMediator mediator, T message, CancellationToken cancellationToken = default);
The same as Send
except that it returns the given message.
IParticipant
public interface IParticipant<in T>
{
void ProcessMessage(IParticipantContext<T> context);
}
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>
calss is also available on this class.
Registration
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 ComponentRegistryExtensions.RegisterMediator(IComponentRegistry)
.
The participants may be registered using the following ComponentRegistryExtensions
methods:
public static void RegisterMediatorParticipants(this IComponentRegistry registry, Assembly assembly);
Considerations
If you have a rather predictable sequential workflow and you require something faster execution then you may wish to consider the Shuttle.Core.Pipelines package. A performance testing application for your use-case would be able to indicate the more suitable option.
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. |
.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 is compatible. |
.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. |
-
- Shuttle.Core.Container (>= 12.0.1)
- Shuttle.Core.Reflection (>= 11.0.3)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Shuttle.Core.Mediator:
Package | Downloads |
---|---|
Shuttle.Access.Application
A client component that calls the Shuttle.Access.WebApi to interact with the Shuttle.Access Identity and Access Management domain. |
|
Shuttle.Core.Mediator.OpenTelemetry
OpenTelemetry instrumentation for Shuttle.Core.Mediator implementations. |
GitHub repositories
This package is not used by any popular GitHub repositories.