Interface IDispatcher
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:
- IStreamingDispatcher for streaming document dispatch
- IProgressDispatcher for progress-reporting dispatch
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
messageTMessageThe message instance.
contextIMessageContextContext for the dispatch operation.
cancellationTokenCancellationTokenToken used to cancel the operation.
Returns
- Task<IMessageResult>
The result of dispatch execution.
Type Parameters
TMessageType 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
messageTMessageThe message instance.
contextIMessageContextContext for the dispatch operation.
cancellationTokenCancellationTokenToken used to cancel the operation.
Returns
- Task<IMessageResult<TResponse>>
The result including the response value.
Type Parameters
TMessageType of message being dispatched.
TResponseExpected response type.