Table of Contents

Class Mediator

Namespace
Arbiter.Mediation
Assembly
Arbiter.Mediation.dll

A default implementation of the IMediator interface.

public sealed class Mediator : IMediator
Inheritance
Mediator
Implements
Inherited Members

Constructors

Mediator(IServiceProvider, IMediatorDiagnostic?)

A default implementation of the IMediator interface.

public Mediator(IServiceProvider serviceProvider, IMediatorDiagnostic? diagnostic = null)

Parameters

serviceProvider IServiceProvider

Service provider to resolve handlers and behaviors.

diagnostic IMediatorDiagnostic

An optional diagnostic service for logging activities and metrics.

Exceptions

ArgumentNullException

Thrown when serviceProvider is null

Methods

Publish<TNotification>(TNotification, CancellationToken)

Sends a notification to multiple handlers.

public ValueTask Publish<TNotification>(TNotification notification, CancellationToken cancellationToken = default) where TNotification : INotification

Parameters

notification TNotification

The notification to send.

cancellationToken CancellationToken

Cancellation token.

Returns

ValueTask

Awaitable task for the notification operation.

Type Parameters

TNotification

The type of notification being sent.

Exceptions

ArgumentNullException

Thrown when notification is null.

Send(object, CancellationToken)

Sends a request to the appropriate handler and returns the response.

public ValueTask<object?> Send(object request, CancellationToken cancellationToken = default)

Parameters

request object

The request to send to the handler. The request object must implement IRequest<TResponse> interface.

cancellationToken CancellationToken

Cancellation token.

Returns

ValueTask<object>

Awaitable task returning the handler response.

Exceptions

ArgumentNullException

Thrown when request is null.

InvalidOperationException

Thrown when request does not implement IRequest<TResponse> interface.

Send<TResponse>(IRequest<TResponse>, CancellationToken)

Sends a request to the appropriate handler and returns the response.

public ValueTask<TResponse?> Send<TResponse>(IRequest<TResponse> request, CancellationToken cancellationToken = default)

Parameters

request IRequest<TResponse>

The request to send to the handler.

cancellationToken CancellationToken

Cancellation token.

Returns

ValueTask<TResponse>

Awaitable task returning the TResponse.

Type Parameters

TResponse

The type of response from the handler.

Exceptions

ArgumentNullException

Thrown when request is null.

Send<TRequest, TResponse>(TRequest, CancellationToken)

Sends a request to the appropriate handler and returns the response.

public ValueTask<TResponse?> Send<TRequest, TResponse>(TRequest request, CancellationToken cancellationToken = default) where TRequest : IRequest<TResponse>

Parameters

request TRequest

The request to send to the handler.

cancellationToken CancellationToken

Cancellation token.

Returns

ValueTask<TResponse>

Awaitable task returning the TResponse.

Type Parameters

TRequest

The type of request being sent.

TResponse

The type of response from the handler.

Exceptions

ArgumentNullException

Thrown when request is null.