I know that a multi-entity Aggregate can support a child entity where said entity is a child of the Aggregate root and indicated by @AggregateMember
. Does Axon also support the scenario where the child entity has its own child entity?
Hello and welcome Kurt,
I have personally never needed that. But it’s an interesting question. Have you tried it and found it’s not working? Or do you need official confirmation of the intended behavior?
Hi Milen, it was more for official confirmation, based on the absence of something like an @EntityMember???
I see. In this case, we need to wait for some of the framework folks to confirm the intended behavior. Meanwhile, you can do a simple test and see what the result is.
Hi Kurt, Milen,
I think I can provide some guidance on the matter, so let me do that.
Axon Framework supports any number of nested entities within an Aggregate.
You could thus do something like this if the domain model requires you so:
class MyAggregate {
@AggregateMember
private FirstLevelEntity firstLevelEntity;
// omitting command handlers, state and event sourcing handlers
}
class FirstLevelEntity {
@AggregateMember
private SecondLevelEntity secondLevelEntity;
@AggregateMember
private AnotherSecondLevelEntity anotherSecondLevelEntity;
// omitting command handlers, state and event sourcing handlers
}
class SecondLevelEntity {
// omitting command handlers, state and event sourcing handlers
}
class AnotherSecondLevelEntity {
@AggregateMember
private ThirdLevelEntity secondLevelEntity;
// omitting command handlers, state and event sourcing handlers
}
class ThirdLevelEntity {
// omitting command handlers, state and event sourcing handlers
}
If you want a more workable piece of code, you can look at the ComplexAggregateStructureTest
here.
This test contains the model of a Book
aggregate, containing Page
entities, which in turn contain Paragraph
entities.
I hope this helps you further @kurtpste!
Excellent. Thanks a bunch Steven and Milen. Much appreciated.