Architecture Decision Record
ADR-083: One CRUD Lifecycle Event per Entity with a State Discriminator
Status
Accepted (2026-08-14). Revised 2026-08-23: the adopter counts were refreshed (ADC Conference's
ActivityChanged joined the base-derived set) and three source citations were re-anchored.
Revised 2026-08-31: the lifecycle-event totals were recounted from source (32 across the three
apps, of which 8 are in Store), the selective-handler example was re-anchored to
SpeakerDeletedHandler (the previously cited SessionCreatedHandler and its test exist nowhere in
MMCA.ADC), and the Sales consumer's filter citation was re-anchored.
Revised 2026-09-11: Store's ProductReviewChanged was added to both adopter counts (33 lifecycle
events across the three apps, 9 of them in Store; 15 records derive the base), the wire
discriminator's type was corrected to Catalog's own ProductChangeState, the Sales consumer was
re-anchored to ProductVariantChangedHandler (which handles Added and Updated), and the
Session, OrderPaid and contract-test citations were re-anchored.
Revised 2026-09-19: both counts were recounted from source and raised. ADC Conference's
PartnerChanged and SessionAssetChanged were missing from the base-derived set, so 17 records now
derive EntityChangedEvent<TId> across the four repos (19 including the MMCA.ECommerce sample), and
the shape sweep finds 35 lifecycle events across the three apps (25 in ADC, of which 18 are in
Conference; 9 in Store; 1 in Helpdesk).
Revised 2026-10-06: Session now raises SessionChanged from four sites (a second Updated from
UnassignRoom), and the stale source citations were re-anchored.
Revised 2026-10-21: the list of integration-event fitness rules now names the [EventName],
*.IntegrationEvents namespace, upcaster and payload-purity rules, records the domain-free purity
rule as a partial enforcer of the Shared-typed wire discriminator, and the contract snapshot
builder citation was re-anchored after the [EventName] rule landed above it.
Updated 2026-10-28: the MMCA.ECommerce sample is retired, so its two adopters leave the count (17
records derive the base, all in the four repos).
Revised 2026-11-23: ProductVariantChanged's doc no longer names the four events it replaced, so
the Decision now quotes what it says, OrderPaid is recorded as also carrying the frozen savings,
and the stale source anchors were refreshed.
Context
ADR-003 decides how a domain event moves: captured into the outbox inside SaveChangesAsync,
dispatched in-process after commit, or published to the broker when it is an integration event.
ADR-010 decides how a cross-boundary event contract evolves. Neither decides what an event is,
and that question lands on every new aggregate on its first day: does creating, editing and
soft-deleting a Session raise SessionCreated, SessionChanged and SessionDeleted, or one event
that says which of the three happened?
The {Entity}Created / {Entity}Changed / {Entity}Deleted triple is the default answer in most DDD
samples, and it scales badly in a modular monolith: three record types, three Scrutor-scanned handler
registrations and three serialized outbox payload shapes per entity, so a module with eight aggregates
carries twenty-four event types before a single business rule is expressed. It also splits the
subscriber's view. A handler that wants "something happened to this session" implements three
interfaces and has to keep three implementations in agreement, and adding a fourth transition later
means touching all of them.
Decision
Every generic CRUD lifecycle transition of an entity raises one event type for that entity,
carrying a DomainEntityState discriminator; handlers filter on State.
- One base record, two members.
EntityChangedEvent<TIdentifierType>(DomainEntityState State, TIdentifierType EntityId) : BaseDomainEvent, constrainedwhere TIdentifierType : notnull(MMCA.Common/Source/Core/MMCA.Common.Domain/DomainEvents/EntityChangedEvent.cs:24-27). Its own XML doc states the intent: consolidate the{Entity}Created/{Entity}Changed/{Entity}Deletedpattern "into a single event type per entity" (:6-8). Deriving fromBaseDomainEventmeans every lifecycle event inherits theMessageId+DateOccurredenvelope with no extra members (.../DomainEvents/BaseDomainEvent.cs:28,35). - The discriminator is a four-member enum, three of which are ever raised.
DomainEntityStateisUnchanged = 0,Added = 1,Updated = 2,Deleted = 3(MMCA.Common/Source/Core/MMCA.Common.Domain/Enums/DomainEntityState.cs:7-13). No production call site in any repo raisesUnchanged: it is the zero default, and it appears only as a negative[InlineData]case in a handler test, whose helper has to hand-build the event because no transition on the aggregate produces one (MMCA.ADC/Tests/Modules/Engagement/MMCA.ADC.Engagement.Application.Tests/Points/DomainEventHandlers/SessionQuestionSubmittedPointsHandlerTests.cs:69,193-210). Addedfrom the factory,Updatedfrom mutators,DeletedfromDelete(). The base's usage note fixes the mapping (EntityChangedEvent.cs:10-13), andSessionis the canonical shape: one event type, four raise sites, inMMCA.ADC/Source/Modules/Conference/MMCA.ADC.Conference.Domain/Sessions/Session.cs:242(Added, from the static factory),:304(Updated, fromUpdate),:323(Updated, fromUnassignRoom) and:344(Deleted, inside theDeleteoverride once the base soft delete and the child cascade succeed), all constructing the sameSessionChanged(.../Sessions/DomainEvents/SessionChanged.cs:13-18).- Handlers filter on
State, or deliberately do not. The points award for asking a question subscribes toSessionQuestionChangedand returns immediately unless the state isAdded(MMCA.ADC/Source/Modules/Engagement/MMCA.ADC.Engagement.Application/Points/DomainEventHandlers/SessionQuestionSubmittedPointsHandler.cs:65-69). A handler that genuinely wants every transition writes no filter and logs the discriminator instead:TicketChangedAuditHandlerpassesdomainEvent.Statestraight into itsLoggerMessagetemplate (MMCA.Helpdesk/Source/Modules/Tickets/MMCA.Helpdesk.Tickets.Application/Tickets/DomainEventHandlers/TicketChangedAuditHandler.cs:23,28-29). - Business state-machine transitions keep their own event types. The base's doc scopes it to
generic CRUD and directs events such as
OrderPaidandShoppingCartCheckedOutto inheritBaseDomainEventdirectly (EntityChangedEvent.cs:16-19), which is what they do:OrderPaidcarries a customer, a frozen total and savings, and an order-line snapshot (MMCA.Store/Source/Modules/Sales/MMCA.Store.Sales.Domain/Orders/DomainEvents/OrderPaid.cs:22-28), andShoppingCartCheckedOutnames the checkout transition rather than an update (.../Sales.Domain/ShoppingCarts/DomainEvents/ShoppingCartCheckedOut.cs:6-8, raised at.../ShoppingCarts/ShoppingCart.cs:118). The test is payload plus intent: a transition with a name a business person uses and fields no other transition carries gets its own type. - The discriminator rides the wire, and it is frozen there. Store's cross-module Catalog contract
puts the discriminator first on a
BaseIntegrationEvent(MMCA.Store/Source/Modules/Catalog/MMCA.Store.Catalog.Shared/Products/IntegrationEvents/ProductVariantChanged.cs:34-35) and its doc states that one event covers every variant lifecycle change (add; SKU, price or discount update; removal), told apart byState(:9-10). On the wire the discriminator is not the framework enum but Catalog's ownProductChangeState, declared with the same member names and ordinals because every type on a public contract has to live in a*.Sharedassembly a consumer may reference whileDomainEntityStateships from a*.Domainone (.../IntegrationEvents/ProductChangeState.cs:7-12). The Sales consumer takesAddedandUpdatedand stops onDeleted(MMCA.Store/Source/Modules/Sales/MMCA.Store.Sales.Application/Inventory/DomainEventHandlers/ProductVariantChangedHandler.cs:56-59). Because integration-event shapes are snapshot-frozen by an architecture test (MMCA.Common/Source/Hosting/MMCA.Common.Testing.Architecture/Rules/Contracts/ArchitectureRules.Events.cs:56-73),State:ProductChangeStateis a committed line of the wire contract (MMCA.Store/Tests/Architecture/MMCA.Store.Architecture.Tests/Contracts/IntegrationEventContractTests.cs:12, and the siblingProductInfoChangedentry at:11carries it too), so retyping or removing the discriminator fails the build and, under ADR-010, requires a new event type rather than a silent reshape. - The shared base is the convenience; the discriminator shape is the convention. Seventeen concrete
records derive
EntityChangedEvent<TId>across the four repos: seven in Store (OrderChanged.cs:18,ShoppingCartChanged.cs:15,InventoryItemChanged.cs:16underSales.Domain,Catalog.Domain/Products/DomainEvents/ProductChanged.cs:23,Catalog.Domain/Categories/DomainEvents/CategoryChanged.cs:19,Catalog.Domain/Reviews/DomainEvents/ProductReviewChanged.cs:15-20,Identity.Domain/Customers/DomainEvents/CustomerChanged.cs:24), nine in ADC Conference (SponsorChanged.cs:16,EventChanged.cs:16,QuestionChanged.cs:16,CategoryChanged.cs:16,ActivityChanged.cs:16,SpeakerChanged.cs:21,SessionChanged.cs:18,PartnerChanged.cs:16,SessionAssetChanged.cs:18), and one in Helpdesk (TicketChanged.cs:15). Eighteen further domain events follow the same one-event-with-Stateshape while inheritingBaseDomainEventdirectly (ProductVariantChangeddoes the same overBaseIntegrationEventon the wire), either because they identify a parent/child pair rather than a single entity (RoomChangedcarriesEventId+RoomId,MMCA.ADC/Source/Modules/Conference/MMCA.ADC.Conference.Domain/Events/DomainEvents/RoomChanged.cs:13-18;ShoppingCartItemChangedcarriesCustomerId+ProductVariantId,MMCA.Store/Source/Modules/Sales/MMCA.Store.Sales.Domain/ShoppingCarts/DomainEvents/ShoppingCartItemChanged.cs:16-22;ProductImageChangedcarriesProductId+ImageId,MMCA.Store/Source/Modules/Catalog/MMCA.Store.Catalog.Domain/Products/DomainEvents/ProductImageChanged.cs:15-20) or because the module took the shape without the base (all seven ADC Engagement events, for exampleMMCA.ADC/Source/Modules/Engagement/MMCA.ADC.Engagement.Domain/UserSessionBookmarks/DomainEvents/UserSessionBookmarkChanged.cs:21-26, whose doc cites the same rule as BR-60 at:8-9). Counting the shape rather than the base type, a sweep of everyDomainEvents/*.csdeclaring aDomainEntityState Statemember finds 25 in ADC (18 Conference, 7 Engagement; Identity's two events are business-specific and carry no discriminator), 9 in Store (of twenty-three domain events there, the other fourteen name business transitions) and 1 in Helpdesk: 35 in total. - Nothing enforces the taxonomy. The shared fitness rules require domain events to be sealed and to
live in a
*.DomainEventsnamespace (MMCA.Common/Source/Hosting/MMCA.Common.Testing.Architecture/Rules/Governance/ArchitectureRules.Naming.cs:66-75), to be immutable (MMCA.Common/Source/Hosting/MMCA.Common.Testing.Architecture/Rules/Domain/ArchitectureRules.Immutability.cs:34-38), and require integration events to inheritBaseIntegrationEventand declare anint SchemaVersion(MMCA.Common/Source/Hosting/MMCA.Common.Testing.Architecture/Rules/Contracts/ArchitectureRules.Events.cs:6-25), carry[EventName](:33-41) and live in a*.IntegrationEventsnamespace, inside the Shared layer when the repo has modules (:44-54); the same base also checks the upcasters (MMCA.Common/Source/Hosting/MMCA.Common.Testing.Architecture/Bases/Contracts/EventConventionTestsBase.cs:26-30). Two purity rules require an integration event to ship from a*.Sharedassembly and to expose no type from a.Domainassembly on its wire shape (MMCA.Common/Source/Hosting/MMCA.Common.Testing.Architecture/Rules/Contracts/ArchitectureRules.IntegrationEventPurity.cs:18-34,56-78, run by.../Bases/Contracts/IntegrationEventPayloadPurityTestsBase.cs:38,41, which all four repos subclass). No rule mentionsEntityChangedEventor the discriminator. The one partial exception is the domain-free rule: it rejectsDomainEntityState(declared inMMCA.Common.Domain) on any integration event (ArchitectureRules.IntegrationEventPurity.cs:105-108,151-152), so it does enforce that a wire discriminator is a Shared type such asProductChangeState, without checking that one exists or what it is called. The framework's own coverage of the base is five unit tests over two test doubles, oneint-keyed and oneGuid-keyed (MMCA.Common/Tests/Core/MMCA.Common.Domain.Tests/DomainEvents/EntityChangedEventTests.cs:10-59, doubles at:63-69).
The seed ships with the pattern, so an adopter starts on it. Helpdesk's TicketChanged is the
reference adopter
(MMCA.Helpdesk/Source/Modules/Tickets/MMCA.Helpdesk.Tickets.Domain/Tickets/DomainEvents/TicketChanged.cs:12-15),
and because the MMCA.Templates pack is staged from that tree rather than from a copy (ADR-065), it is
also what dotnet new mmca-app hands over. The seed also shows the one hole in "Added from the
factory": Ticket's identifier is database-generated, so it is still 0 at factory time and the
aggregate deliberately raises no Added event, with creation signalled after commit by a separate
integration event instead
(.../Tickets.Domain/Tickets/Ticket.cs:81-84, published at
.../Tickets.Application/Tickets/UseCases/Create/CreateTicketHandler.cs:43-45); the audit handler's doc
records exactly that gap (TicketChangedAuditHandler.cs:13-14).
Rationale
- One type per entity is one subscription surface. A subscriber declares interest in the entity, then decides which transitions matter, instead of the container deciding for it across three registrations that can drift apart.
- The triple multiplies types without adding information.
SessionCreated,SessionChangedandSessionDeletedwould carry the same identifier and the same fields; the only thing that differs is the verb, which is precisely what an enum member expresses. - The shape survives extraction. The same record is the in-process domain event in the monolith and the serialized outbox payload once the module runs as a service (ADR-003 / ADR-008). Collapsing three types into one shrinks the contract surface a consumer must learn and the wire snapshot must freeze.
- The carve-out keeps the model honest. A CRUD discriminator is the right answer for "a row
changed" and the wrong answer for "payment cleared":
OrderPaidcarries an order-line snapshot precisely so downstream handlers do not re-query inside an uncommitted transaction (OrderPaid.cs:19-21). Folding that into a lifecycle base would hang a nullable business payload off every entity's event. - Adding a transition is cheap. A new lifecycle state is an enum member plus handler branches, not a new record, a new registration and a new payload shape.
Trade-offs
- Every selective handler pays a filter. A handler that cares about one transition has to open with
a
Stateguard and return (SessionQuestionSubmittedPointsHandler.cs:65-69is the shape to copy); omit it and the handler fires on all three. The compiler cannot help, because the wrong behavior is an extra silent invocation, not a build error. - The subscription surface is coarser. Subscribing means subscribing to the whole entity lifecycle: the dispatcher invokes every subscriber on every transition and the handler decides. With separate types the container would only ever call a creation handler on creation. Granularity is per entity, not per transition.
- The business-event line is a judgment call, not a rule. Nothing checks whether a transition
deserves its own type, and
LivePollChangedsits right on the line: it folds Created/Opened/Closed/Deleted into one event and carries the poll'sLivePollStatusso handlers can tell the transitions apart (MMCA.ADC/Source/Modules/Engagement/MMCA.ADC.Engagement.Domain/LivePolls/DomainEvents/LivePollChanged.cs:9-11,17-22), which is a state machine expressed through the CRUD shape rather than as its own events. - The base type is optional in practice. 17 of the 35 lifecycle events across the three apps derive
EntityChangedEvent<TId>; the other 18 re-declare the same two members onBaseDomainEvent. Consistency is a review convention, not a fitness function (ADR-015), so a new module can drift without a failing test. - A padded payload where an entity only ever does one thing.
PointsEntryChangedcarries aStatethat is alwaysAddedbecause the ledger is append-only, and its doc says so (MMCA.ADC/Source/Modules/Engagement/MMCA.ADC.Engagement.Domain/Points/DomainEvents/PointsEntryChanged.cs:8-10,17-23). The uniform shape wins over a slimmer event. Unchangedis reachable and meaningless. It is the enum's zero value, so a default-constructed or partially deserialized event reads asUnchangedrather than failing loudly. Handlers that filter positively for the state they want are unaffected; a handler written as a two-branch test overAddedversus everything else would silently treat it as the second branch.- A wire discriminator is a versioning obligation. Once
Stateis in the frozen contract (IntegrationEventContractTests.cs:12), the enum's member values are part of the payload: adding a member is additive, but renumbering or removing one is a breaking change under ADR-010.
Alternatives rejected
- Splitting each
XChangedevent into per-fact past-tense events (SpeakerRenamed,SessionCancelled, and so on) with every handler and bridge updated to match. Proposed 2026-08-26, after a naming audit flagged ADC's roughly 20 CRUD-shaped domain events as diverging from past-tense-fact naming, and declined the same day. The one-event-per-aggregate convention this record decides is deliberate; integration events are separately past-tense and stay that way; and the churn of renaming high-traffic events plus every handler was judged not worth the purity. Handler-side state filtering (the question-points handler narrowing toAdded) is conformant with this record, not a smell. - A past-tense naming fitness rule in
EventConventionTestsBase. Rejected alongside the rename, and for a stronger reason: the rule would fail the build on the convention this ADR accepts.
Revision (2026-10-06)
Sessionhas fourSessionChangedraise sites, not three:UnassignRoom(O-60) raises a secondUpdated(Session.cs:324) alongsideUpdate(:305); still one event type, and everyUpdatedcomes from a mutator. TheDeletedraise now sits in theDeleteoverride after the base soft delete and the child cascade (:345).- Source citations re-verified against current code and re-anchored:
Session.cs(:243,:305,:324,:345), the hand-builtUnchangedtest helper (SessionQuestionSubmittedPointsHandlerTests.cs:79,203-220), theAddedguard (SessionQuestionSubmittedPointsHandler.cs:66-70) and the contract snapshot builder (ArchitectureRules.Events.cs:40-57).
Revision (2026-10-21)
Re-verified against current source. The taxonomy, the adopter counts and the frozen wire discriminator are unchanged; the contract snapshot builder moved down when a new integration-event rule was inserted above it.
- The "Nothing enforces the taxonomy" list now also names the rules that integration events carry
[EventName](ArchitectureRules.Events.cs:33-41) and live in a*.IntegrationEventsnamespace (:44-54), the two upcaster rules (EventConventionTestsBase.cs:26-30) and the two payload-purity rules (ArchitectureRules.IntegrationEventPurity.cs:18-34,56-78, wired in all four repos throughIntegrationEventPayloadPurityTestsBase.cs:38,41). No rule namesEntityChangedEventor the discriminator, but the domain-free purity rule is a partial exception: it rejectsDomainEntityStateon the wire (ArchitectureRules.IntegrationEventPurity.cs:105-108,151-152), which enforces the Decision's point that the wire discriminator is a Shared type such asProductChangeState. - Anchors re-verified against current source: the contract snapshot builder
(
ArchitectureRules.Events.cs:56-73, keyed by[EventName]inContractKeyat:93-105) and the twoState:ProductChangeStatecontract lines (IntegrationEventContractTests.cs:11-12, keyedCatalog.ProductInfoChanged.v1andCatalog.ProductVariantChanged.v1).
Revision (2026-11-23)
Re-verified against current source. The taxonomy, the four Session raise sites and their state
mapping, the selective-handler guards and the adopter counts (17 records derive the base: 7 Store,
9 ADC, 1 Helpdesk) are unchanged; two payload descriptions moved and several anchors shifted.
ProductVariantChanged's doc no longer lists the four events it consolidated. It now says one event covers every variant lifecycle change (add; SKU, price or discount update; removal), told apart byState(MMCA.Store/Source/Modules/Catalog/MMCA.Store.Catalog.Shared/Products/IntegrationEvents/ProductVariantChanged.cs:9-10), and no file underMMCA.Store/Source/namesProductVariantAdded,ProductVariantRemoved,ProductVariantSkuChangedorProductVariantPriceChanged(the integration test namesProductVariantAddedConsistencyTestsandProductVariantAdded_*keep the old event name for the add case of the consolidated event). The Decision bullet now quotes the doc as it reads. The record and its leadingState(:34-35) are unchanged.OrderPaidalso carries a frozenTotalSavingsbeside the total (MMCA.Store/Source/Modules/Sales/MMCA.Store.Sales.Domain/Orders/DomainEvents/OrderPaid.cs:26, doc:15-18). It still inheritsBaseDomainEventdirectly (:28), and the rationale for its line snapshot (no re-query inside an uncommitted transaction) is theOrderLinesdoc at:19-21.- Anchors re-verified against current source:
Session.cs:242(Added, inCreateat:195),:304(Updated, inUpdateat:265),:323(Updated, inUnassignRoomat:316) and:344(Deleted, in theDeleteoverride at:333, afterbase.Delete()at:341); theUnchangedtest case and its hand-built helper (SessionQuestionSubmittedPointsHandlerTests.cs:69,193-210); theAddedguard (SessionQuestionSubmittedPointsHandler.cs:65-69); theDeletedguard (SpeakerDeletedHandler.cs:30-31); theOrderPaidrecord (OrderPaid.cs:22-28); and the Store base-derived recordsOrderChanged.cs:18,ShoppingCartChanged.cs:15,InventoryItemChanged.cs:16(underSales.Domain/Inventory/DomainEvents) andCustomerChanged.cs:24.
Related
ADR-003 (how these events are captured and dispatched; this ADR decides only their shape), ADR-010
(schema versioning for the discriminator once it crosses a service boundary), ADR-008 (the extraction
that turns the same record into a wire payload), ADR-015 (fitness functions: the taxonomy is
deliberately not one of them), ADR-021 (consumer-side dedup on the MessageId this base inherits),
ADR-065 (the template pack that ships the pattern to adopters).