Type to search pages and rules.

Browse pages

LS2005: Handler Name Lacks Its Command or Query Suffix

LS2005 is a compiler check that reports a command or query handler, the type that runs a use case, whose name does not state which of the two it runs, so the model builder cannot tell a write from a read by its file name. This page states what the rule reports, where the error sits, and how to complete the handler name.

Markdown

Reference#

What the Rule Enforces#

LS2005 enforces Use architectural suffixes (litespec/workspace/naming#use-architectural-suffixes). It runs in Application and Infrastructure. Its category is LiteSpec.Layers. It reports an error and is enabled by default, as the Analyzers overview describes.

What the Rule Reports#

The rule reports a class that implements an interface named ICommandHandler unless its name ends in CommandHandler, and a class that implements an interface named IQueryHandler unless its name ends in QueryHandler. The diagnostic sits on the type name, and its message names the contract and the required suffix.

Failing Example#

C#
internal sealed class PlaceOrderUseCase : ICommandHandler<PlaceOrderCommand, int>
{
}

Passing Example#

C#
internal sealed class PlaceOrderCommandHandler : ICommandHandler<PlaceOrderCommand, int>
{
}

How to Fix#

End the class name in CommandHandler for a command and in QueryHandler for a query, keeping the use-case prefix the file name carries.

Notes#

What the Rule Ignores#

The rule does not report a class that implements neither contract, even when its name ends in Handler, and it does not report interfaces. It does not run in Domain, Application.Abstractions, or WebApi.