Event

annotation class Event(val revision: String = DEFAULT_REVISION)

Marks a class as a domain event in domain-driven design (DDD).

Domain events represent something that happened in the domain that is of interest to other parts of the system. They are immutable records of state changes that have occurred within aggregates.

Key characteristics of domain events:

  • Are immutable (no setters, all properties are read-only)

  • Represent past occurrences ("OrderCreated", not "CreateOrder")

  • Contain all data necessary to understand what happened

  • Are named in past tense

  • May trigger side effects in other aggregates or external systems

Example usage:

@Event
data class OrderCreated(
val orderId: String,
val customerId: String,
val items: List<OrderItem>,
val totalAmount: BigDecimal,
val createdAt: Instant = Instant.now()
)

@Event(revision = "2.0")
data class OrderShipped(
val orderId: String,
val trackingNumber: String,
val shippedAt: Instant = Instant.now()
)

Parameters

revision

Optional version number for the event schema. Used for event versioning and migration. Defaults to the framework's default revision.

See also

for aggregates that publish events

for event handler methods

Properties

Link copied to clipboard