Skip to content

ADR-002: Domain Entities Stay POCO

Status

Accepted

Context

Domain rules like "a private note is visible only to its author" need one authoritative home. A rich domain model (e.g. a Note aggregate owning visibility and item ordering behavior) was considered when deepening the Notes module.

Decision

Entities carry data only — no behavior, no domain methods. Feature-level query rules live in IQueryable extension methods colocated with the feature (e.g. NoteQueryExtensions.AccessibleTo(userId)), and cross-cutting rules live in named global query filters. Ordering logic stays behind DI service interfaces (e.g. INoteOrderingService).

Consequences

  • Rules compose inside LINQ-to-SQL and translate to server-side SQL
  • EF Core materialization stays trivial; entities keep required/default! initialization patterns
  • Rich aggregates were rejected: behavior on entities would not translate into queries and would split visibility rules between memory and SQL