Type to search pages and rules.

Browse pages

LS2010: Repository Variable Not Named After Its Interface

LS2010 is a compiler check that reports a repository parameter, field, or local whose name does not follow its interface, so a reader cannot tell which aggregate the variable stages. This page states what the rule reports, where the error sits, and how to name the variable after its interface.

Markdown

Reference#

What the Rule Enforces#

LS2010 enforces Name repository variables after their interface (litespec/workspace/naming#name-repository-variables-after-their-interface). It runs in Application, Infrastructure, and Worker. Its category is LiteSpec.Layers. Severity and enablement follow the Analyzers overview.

What the Rule Reports#

The rule reports a parameter, field, or local whose type is an interface named I{Name}Repository and whose name is not {name}Repository, the interface name without its I prefix starting in lower case. A field may carry one leading underscore. The diagnostic sits on the variable name, and its message names the variable, the interface, and the expected name.

Failing Example#

C#
internal sealed class ApproveExpenseCommandHandler(IExpenseRepository expenses)
{
}

Passing Example#

C#
internal sealed class ApproveExpenseCommandHandler(IExpenseRepository expenseRepository)
{
    private readonly IExpenseRepository _expenseRepository = expenseRepository;
}

How to Fix#

Name the variable after its interface without the I prefix, starting in lower case and ending in Repository, such as expenseRepository for IExpenseRepository.

Notes#

What the Rule Ignores#

The rule does not report a variable whose type is not an interface named I{Name}Repository, including other interfaces and concrete classes. It does not run in Domain or WebApi.