Skip to main content

DISP001: Handler Not Discoverable

PropertyValue
Diagnostic IDDISP001
TitleHandler may not be discoverable
CategoryExcalibur.Dispatch.Handlers
SeverityWarning
Enabled by defaultYes

Cause

A class implements IDispatchHandler<T> but may not be discovered by the source generators. This typically happens when:

  • The handler is missing the [AutoRegister] attribute
  • The handler is not in an assembly that is scanned during source generation

Example

The following code triggers DISP001:

// Warning DISP001: Handler 'CreateOrderHandler' implements IActionHandler<CreateOrder>
// but may not be discovered by source generators
public class CreateOrderHandler : IActionHandler<CreateOrder>
{
public Task HandleAsync(CreateOrder action, CancellationToken cancellationToken)
{
// ...
return Task.CompletedTask;
}
}

How to Fix

Option 1 (Recommended): Add the [AutoRegister] attribute:

[AutoRegister]
public class CreateOrderHandler : IActionHandler<CreateOrder>
{
public Task HandleAsync(CreateOrder action, CancellationToken cancellationToken)
{
// ...
return Task.CompletedTask;
}
}

Option 2: Register the handler manually in DI:

services.AddTransient<IActionHandler<CreateOrder>, CreateOrderHandler>();

When to Suppress

Suppress this warning if you intentionally register handlers manually and do not use the source generator for discovery:

#pragma warning disable DISP001
public class CreateOrderHandler : IActionHandler<CreateOrder>
#pragma warning restore DISP001

See Also