Hi Jerry,
the English came across fine. I hope this message also gets properly translated back.
There are a lot of questions I have around the design. Why is there a “Group” aggregate and a “Member” aggregate? I understand they are conceptually different entities and in terms of information, capture different aspects. However, in command processing, the model should be based on expected behavior. In your case, you expect that adding a member to a group with 2000 members will fail. Ideally, that means that the Group aggregate has something inside that knows when there are 2000 members.
One way to achieve this is by modelling something that represents Member inside the Group. Whether that is really a solution for you, I wouldn’t be able to say. It depends on many factors.
Another way, and that might be the simplest solution from here, is by executing a query or invoking a service that will give you the number of members inside the group.
If you use Spring, then you can simply add your MemberService as a parameter, just like Michael suggested. Axon will take the Spring Bean when invoking your method.
If you don’t use Spring, you can register an instance in the Axon Configuration API as follows:
Configurer configurer = // define your configuration
configurer.registerComponent(MemberService.class, c-> new MemberService()); // instead of creating “new”, you will probably want to inject your existing service instance.
Any components registered in the Configuration, are available for use as parameters in @CommandHandler methods.
I hope this helps (and not too much is lost in translation
).
Kind regards,