Browse pages
LS1004: State Case Is Not Sealed
LS1004 is a compiler check that reports a lifecycle state case in Domain, the project that holds business rules, left open for extension, which lets a later type add states the business never defined and stops type switches from checking every case. This page states what the rule reports, where the warning sits, and how to seal the case.
Reference#
What the rule enforces#
LS1004 enforces Model every Aggregate lifecycle with state records (litespec/backend/dotnet/domain#model-every-aggregate-lifecycle-with-state-records). It runs in Domain only. Its category is LiteSpec.Domain. It reports a warning and is enabled by default, as the Analyzers overview describes. It decides at the end of compilation, after every type is known.
What the rule reports#
The rule reports a non-abstract, non-sealed class that derives directly from a recognized state base. A state base is an abstract record whose name ends in State and either matches {Aggregate}State or is an aggregate State property type. The diagnostic sits on the case name.
Failing example#
public abstract record OrderState;
public record OrderDraftState : OrderState;Passing example#
public abstract record OrderState;
public abstract record OrderOpenState : OrderState;
public sealed record OrderDraftState : OrderOpenState;How to fix#
Mark the case sealed, or mark it abstract when it is a genuine intermediate with its own sealed cases.
Notes#
What the rule ignores#
The rule does not report sealed cases or abstract intermediate cases. It does not run outside Domain.