问题
I honestly have no idea where to begin. The repository aspect is relatively simple but I cannot seem to find any information on how to delete an aggregate root via the CommandGateway.
Any directions and/or documentation on how to achieve this would be greatly appreciated.
回答1:
Putting this here for future reference for anyone else that might be as lost as I was initially.
When using the Event Sourcing Aggregate, one can make use of the markDeleted() static method on the Aggregate in question. I placed mine in the @EventSourcingHandler
import static org.axonframework.modelling.command.AggregateLifecycle.markDeleted;
@EventSourcingHandler
public void on(DeletedEvent event){
markDeleted();
}
Further information can be found at: https://docs.axoniq.io/reference-guide/implementing-domain-logic/command-handling/aggregate#aggregate-lifecycle-operations
To delete the view data associated with the aggregate I used an external @EventHandler:
@EventHandler
public void on(DeletedEvent event, ReplayStatus status){
entityRepo.deleteById(event.getId());
}
Thanks to Allard for engaging me in the comments section.
来源:https://stackoverflow.com/questions/59695175/axon-framework-delete-aggregate-root