Closed haisi closed 6 months ago
As far as I understood the Javadoc of JMoleculesDddRules#entitiesShouldBeDeclaredForUseInSameAggregate
:
An {@link ArchRule} that verifies that fields that implement {@link Entity} within a type implementing {@link AggregateRoot} declare the aggregate type as the owning aggregate.
It describes disallowing references between Aggregates. However, how can I model a nested entity structure belonging to the same Aggregate?
The jmolecules @Entity
annotation expects an Aggregate as its generic T
public interface Entity<T extends AggregateRoot<T, ?>, ID> extends Identifiable<ID> {}
I also tried to model a nested entity structure, but - please correct me if I am wrong - unfortunately it doesn't seem to be possible.
I also asked about this here and gave an example for which I feel like this restrictions limits the way I want to use DDD to properly model my domain. Maybe there is also a misunderstanding on my side though as I don't have a lot of experience regarding DDD? Unfortunately I haven't recieved a reply yet - I would love to discuss this more!
@seekM I've created a PoC PR that does what you want.
This has been polished and merged. Thanks, @haisi! 🙇
given: Aggregate Root (Menu) 1 → N Entity (Category) 1 → N Entity (CategoryItem)
This causes following test failure when running
JMoleculesDddRules.all()
as
JMoleculesDddRules#IsDeclaredToUseTheSameAggregate
fails.I've created a minimal project to reproduce the issue here: https://github.com/haisi/jmolecules-nested-entity