Class Mediator
Default implementation of the mediator pattern
public sealed class Mediator : IMediator
- Inheritance
-
Mediator
- Implements
- Inherited Members
Constructors
Mediator(IServiceProvider, Dictionary<Type, IMessageHandler>, ILogger<Mediator>?)
Default implementation of the mediator pattern
public Mediator(IServiceProvider serviceProvider, Dictionary<Type, IMessageHandler> handlers, ILogger<Mediator>? logger = null)
Parameters
serviceProviderIServiceProviderhandlersDictionary<Type, IMessageHandler>loggerILogger<Mediator>
Methods
InvokeAsync<T>(object, CancellationToken, TimeSpan?)
Execute the message handling for this message synchronously and wait for the response. The message is handled locally and delegates immediately to the appropriate handler.
public Task<T> InvokeAsync<T>(object message, CancellationToken cancellation = default, TimeSpan? timeout = null)
Parameters
messageobjectThe message/request to process
cancellationCancellationTokenCancellation token for async operations
timeoutTimeSpan?Optional timeout for the operation
Returns
- Task<T>
The response of type T from the handler
Type Parameters
TThe expected response type