Skip to main content

DISP006: Message Type Missing Dispatch Interface

PropertyValue
Diagnostic IDDISP006
TitleMessage type should implement a dispatch interface
CategoryExcalibur.Dispatch.Messaging.Handlers
SeverityWarning
Enabled by defaultYes

Cause

A type was used as a type argument to IDispatcher.DispatchAsync<T>() but does not implement any of the dispatch marker interfaces (IDispatchAction<TResponse>, IDispatchEvent, or IDispatchMessage). The dispatcher uses these interfaces for routing decisions -- without them, the message may not be delivered correctly.

Examples

Non-compliant

// Warning DISP006: Type 'PlainObject' does not implement IDispatchAction<T>,
// IDispatchEvent, or IDispatchMessage
public class PlainObject { public string Name { get; set; } }

// Usage:
await dispatcher.DispatchAsync(new PlainObject(), context, ct);

Compliant

// Implements IDispatchAction<string> -- dispatcher knows this is a request-response action
public sealed record CreateOrderCommand : IDispatchAction<OrderId>
{
public string ProductName { get; init; } = string.Empty;
}

// Implements IDispatchEvent -- dispatcher knows this is a multi-handler event
public sealed record OrderCreatedEvent(Guid OrderId) : IDispatchEvent;

How to Fix

Add the appropriate dispatch interface to your message type:

ScenarioInterfaceHandler Type
Request-response (returns a value)IDispatchAction<TResponse>IActionHandler<TAction, TResponse>
Fire-and-forget commandIDispatchAction<Unit>IActionHandler<TAction>
Event (multiple handlers)IDispatchEventIEventHandler<TEvent>
Domain eventIDomainEventIEventHandler<TEvent>

When to Suppress

Suppress this diagnostic when dispatching a dynamic or generic message type where the interface constraint is enforced by the calling infrastructure.