Class Mediator
- Namespace
- Mediarion
- Assembly
- Mediarion.dll
Sends requests to their handler and publishes notifications to theirs.
[RequiresUnreferencedCode("The mediator closes handler and behaviour generics over the request type at run time.")]
[RequiresDynamicCode("The mediator closes handler and behaviour generics over the request type at run time.")]
public class Mediator : IMediator, ISender, IPublisher
- Inheritance
-
Mediator
- Implements
- Derived
- Inherited Members
- Extension Methods
Remarks
A request arrives as an IRequest<TResponse>, so the response type is known
and the request type is not — and the handler and the behaviours are generic over the
request type. Closing those generics needs the run-time type, which is why this is built
on reflection and why it is marked as such: an application published ahead of time gets a
warning from the compiler rather than a failure on the first request.
The closing happens once per request type and the result is kept, so the reflection is paid on the first send and never again.
Constructors
- Mediator(IServiceProvider)
Creates a mediator that resolves its handlers from the given provider.
- Mediator(IServiceProvider, INotificationPublisher)
Creates a mediator with a publishing strategy of its own.
Methods
- Publish(object, CancellationToken)
Publishes a notification whose type is only known at run time.
- Publish<TNotification>(TNotification, CancellationToken)
Publishes a notification.
- Send(object, CancellationToken)
Sends a request whose type is only known at run time.
- Send<TResponse>(IRequest<TResponse>, CancellationToken)
Sends a request and waits for its answer.