AggregateId

Marks a field or property as the aggregate identifier.

The aggregate ID uniquely identifies an instance of an aggregate within its bounded context. This annotation is used by the framework to automatically map command payloads to the correct aggregate instances and to generate routing information.

The annotated field/property should contain a unique identifier that distinguishes one aggregate instance from another. Common types include UUIDs, strings, or custom ID types.

Example usage:

@AggregateRoot
class OrderAggregate(
@AggregateId
val orderId: String
) {

@OnCommand
fun processPayment(command: ProcessPaymentCommand): PaymentProcessed {
// Command processing logic
}
}

// Command targeting the aggregate
data class ProcessPaymentCommand(
@AggregateId
val orderId: String,
val amount: BigDecimal
)

See also

for marking aggregate type names

for marking version fields

AggregateIdCapable

for interfaces that provide aggregate ID access