AggregateRoot
Marks a class as an aggregate root in the domain-driven design pattern.
Aggregate roots are the primary entities in a domain model that:
Encapsulate business logic and state
Ensure consistency boundaries for transactions
Control access to internal entities and value objects
Publish domain events when state changes
Classes annotated with @AggregateRoot will be automatically discovered by the framework and registered for command processing and event sourcing.
Example usage:
@AggregateRoot(commands = [CreateOrderCommand::class, UpdateOrderCommand::class])
class OrderAggregate(
@AggregateId
val orderId: String
) {
private var status: OrderStatus = OrderStatus.PENDING
private val items: MutableList<OrderItem> = mutableListOf()
@OnCommand
fun create(command: CreateOrderCommand): OrderCreated {
// Validate and create order
return OrderCreated(orderId, command.items)
}
@OnEvent
fun onCreated(event: OrderCreated) {
items.addAll(event.items)
status = OrderStatus.CREATED
}
}Parameters
Array of command classes to mount to this aggregate root. This enables command rewriting scenarios where commands can be transformed or validated before processing. Also generates command routes in OpenAPI documentation.
See also
for marking command handler methods
for marking event handler methods
for marking aggregate identifiers