Type to search pages and rules.

Browse pages

LS1007: Domain Event Is Not an Immutable Record

LS1007 is a compiler check that reports a domain event, a record of a completed business fact, that is not an immutable record, which would let callers change the fact after it was raised. This page states what the rule reports, where the warning sits, and how to make the event an immutable record.

Markdown

Reference#

What the rule enforces#

LS1007 enforces Raise immutable domain facts (litespec/backend/dotnet/domain#raise-immutable-domain-facts). It runs in Domain only. Its category is LiteSpec.Domain. It reports a warning and is enabled by default, as the Analyzers overview describes.

What the rule reports#

The rule reports any type that implements an interface named IDomainEvent unless it is a record class whose name ends in Event, with no settable properties and no mutable instance fields. The diagnostic sits on the type name. One type gets one diagnostic even when several checks fail.

Failing example#

C#
public sealed record OrderPlacedEvent : IDomainEvent
{
    public string Note { get; set; } = string.Empty;
}

Passing example#

C#
public sealed record OrderPlacedEvent(OrderId OrderId) : IDomainEvent;

How to fix#

Make the event a record class named {Aggregate}{PastFact}Event that implements IDomainEvent, carries business data only, and exposes its members through init setters or readonly fields.

Notes#

What the rule ignores#

The rule does not report interfaces that merely extend IDomainEvent. It accepts event records with only init setters, readonly fields, static fields, or constants. It does not run outside Domain.