AfterCommand
Marks a function to be executed after a command function completes.
Functions annotated with @AfterCommand are invoked after command processing finishes. If the function returns a non-null value, it will be appended to the event stream as a domain event.
This annotation enables post-command processing such as:
Publishing additional domain events
Triggering side effects
Updating related aggregates
Sending notifications
Example usage:
@AggregateRoot
class OrderAggregate {
@OnCommand
fun createOrder(command: CreateOrderCommand): OrderCreated {
// Create order logic
return OrderCreated(orderId, items)
}
@AfterCommand(include = [CreateOrderCommand::class])
fun afterCreateOrder(command: CreateOrderCommand): OrderNotificationSent? {
// Send notification after order creation
if (shouldSendNotification()) {
return OrderNotificationSent(orderId)
}
return null // No event if notification not needed
}
}Parameters
Array of command types to listen for. Only commands of these types will trigger the function. If empty, all commands are included by default.
Array of command types to exclude from listening. Commands of these types will not trigger the function.
See also
for command handling functions
for the function kind this annotation targets