Table of Contents

Interface IActionHandler<TAction, TResult>

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

Defines a handler for an action that returns a result. This is the recommended handler interface for queries.

public interface IActionHandler<in TAction, TResult> where TAction : IDispatchAction<TResult>

Type Parameters

TAction

The type of action to handle.

TResult

The type of result returned by the handler.

Extension Methods

Remarks

Recommended for most use cases. Return your business type directly; the framework automatically wraps it in IMessageResult<T>. Use exception throwing for failures; the exception mapping middleware converts exceptions to proper failure results.

Common use cases include:

  • Query handlers that fetch and return data
  • Commands that return created entity IDs
  • Validation operations that return detailed results
  • Calculation or transformation operations

For advanced scenarios requiring direct control over IMessageResult<T> (e.g., a result served from cache, custom result metadata), use IDispatchHandler<TMessage> instead.

Methods

HandleAsync(TAction, CancellationToken)

Handles the specified action and returns a result asynchronously.

Task<TResult> HandleAsync(TAction action, CancellationToken cancellationToken)

Parameters

action TAction

The action to handle.

cancellationToken CancellationToken

The cancellation token to observe.

Returns

Task<TResult>

A task containing the result of the action.

Remarks

Implementations should respect the cancellation token and handle exceptions appropriately. The returned result will be wrapped in an IMessageResult by the framework for transport across boundaries.