Interface IActionHandler<TAction>
Defines a handler for an action with no return value. This is the recommended handler interface for commands.
public interface IActionHandler<in TAction> where TAction : IDispatchAction
Type Parameters
TActionThe type of action to handle.
- Extension Methods
Remarks
Recommended for most use cases. The framework automatically wraps the completion in IMessageResult. Use exception throwing for failures; the exception mapping middleware converts exceptions to proper failure results.
Common use cases include:
- Commands that modify system state
- Fire-and-forget operations
- Asynchronous tasks that report completion through events
Handlers are resolved from dependency injection and should be registered with appropriate lifetime (typically scoped or transient).
For advanced scenarios requiring direct control over IMessageResult (e.g., cache hits, custom result metadata), use IDispatchHandler<TMessage> instead.
Methods
HandleAsync(TAction, CancellationToken)
Handles the specified action asynchronously.
Task HandleAsync(TAction action, CancellationToken cancellationToken)
Parameters
actionTActionThe action to handle.
cancellationTokenCancellationTokenThe cancellation token to observe.
Returns
- Task
A task representing the asynchronous operation.
Remarks
Implementations should respect the cancellation token and handle exceptions appropriately. The framework ensures this method is called within the message processing pipeline with proper context.