Table of Contents

Interface IDispatcher

Namespace
Excalibur.Dispatch
Assembly
Excalibur.Dispatch.Abstractions.dll

Defines methods for dispatching messages through the Dispatch pipeline.

public interface IDispatcher
Extension Methods

Remarks

The core interface provides fire-and-forget and request-response dispatch. Streaming and progress features are available via sub-interfaces discoverable through the dispatcher's ServiceProvider:

Properties

ServiceProvider

Gets the service provider used by this dispatcher for resolving dependencies.

IServiceProvider? ServiceProvider { get; }

Property Value

IServiceProvider

The IServiceProvider instance, or null if not available.

Remarks

This property enables convenience extension methods to access DI services like IMessageContextFactory without requiring explicit parameters.

The service provider may be null in unit testing scenarios or when the dispatcher is used outside of a DI container.

Methods

DispatchAsync<TMessage>(TMessage, IMessageContext, CancellationToken)

Dispatches a message without expecting a return value.

Task<IMessageResult> DispatchAsync<TMessage>(TMessage message, IMessageContext context, CancellationToken cancellationToken) where TMessage : IDispatchMessage

Parameters

message TMessage

The message instance.

context IMessageContext

Context for the dispatch operation.

cancellationToken CancellationToken

Token used to cancel the operation.

Returns

Task<IMessageResult>

The result of dispatch execution.

Type Parameters

TMessage

Type of message being dispatched.

DispatchAsync<TMessage, TResponse>(TMessage, IMessageContext, CancellationToken)

Dispatches a message that expects a return value.

Task<IMessageResult<TResponse>> DispatchAsync<TMessage, TResponse>(TMessage message, IMessageContext context, CancellationToken cancellationToken) where TMessage : IDispatchAction<TResponse>

Parameters

message TMessage

The message instance.

context IMessageContext

Context for the dispatch operation.

cancellationToken CancellationToken

Token used to cancel the operation.

Returns

Task<IMessageResult<TResponse>>

The result including the response value.

Type Parameters

TMessage

Type of message being dispatched.

TResponse

Expected response type.