Axon Framework: Delete Aggregate Root

痞子三分冷 提交于 2021-01-28 11:08:45

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!