AggregateId
Marks a field or property as the aggregate identifier.
The aggregate ID uniquely identifies an instance within its named aggregate. This uniqueness is global across tenants: tenant ID is routing and isolation context, not a namespace that permits reusing the same aggregate ID. Two instances of the same aggregate type must therefore never share an ID, even when they belong to different tenants. 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
for interfaces that provide aggregate ID access