Skip to content

AggregateRoot should support recursive data structures (Composite Component pattern) #24

@mlidbom

Description

@mlidbom

The support for nesting Components and Entities within an Aggregate is currently more limited than it should be. It locks the structure down to a specific depth of nesting where the exact type is known at each depth.
This is unacceptably limiting. We should support more dynamic nesting strategies.

  • Recursive data structure. (Composite Component)
  • Unknown subtype at each nesting level. (BranchType1, BranchType2, LeafType1)

Implement example of this Aggregate in the Samples project: Thread/Post Composite Aggregate where the Aggregate is a thread with a name and a root Post that is a recursive structure where each post contains a list of Answers that are also Posts.

Early Solution draft

  • RecursiveEntityCollectionManager generic class that adds the ability to handle recursive structures.
    • Type parameter TParentEntityIdGetter
    • Optional Type parameter TInstanceFactory that specifies a factory class to use for creating the correct subtype of the nested entity.

Questions

  • How do you handle the case where the root is a single object instead of a collection? Such as the Post case that would be used in the sample? Currently entity and nested entity require a collection to work. Would it be OK to simple keep this restriction and leave it up to the implementation of the Aggregate/Entity to ensure that no more root level entities are added?.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions