in Education by
I have a domain model with an aggregate root: public interface IAggregateRoot { public string Id { get; } public string Foo { get; set; } public int Bar { get; set; } public IList Children { get; } } The Children collection tends to get very large and I will be lazy loading it when an IAggregateRoot instance is retrieved through the IAggregateRootRepository. My problem is this; if I want to add an IChildEntity to an IAggregateRoot's Children collection, how can my repository allow me avoid persisting the entire aggregate? For example, let's say my IAggregateRootRepository were to look like the following: public interface IAggregateRootRepository { public IAggregateRoot GetById(string id); public void AddOrUpdate(IAggregateRoot root); } Then I could add to the Children collection by getting an IAggregateRoot instance through IAggregateRootRepository.GetById(), adding the child to the Children collection, then persisting it all through IAggregateRootRepository.AddOrUpdate(). That would, however, persist the entire aggregate root, along with its massive collection of children, every time I add a child entity. I guess I could get around that if my repository looked like: public interface IAggregateRootRepository { public IAggregateRoot GetById(string id); public void AddOrUpdate(IAggregateRoot root); public void AddOrUpdate(IChildEntity child); } But, as I have understood the repository pattern, a repository should only deal with aggregate roots and the solution above certainly breaks that requirement. Are there other, better, ways of avoiding this problem? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Aggregate roots should be designed around write boundaries - that is, anything that typically gets written to the database in a single batch/transaction. If you're finding that you need to individually persist child entities which aren't roots, it might be time to reconsider your design, and make your child entity a distinct aggregate root itself (since it has a separate write boundary). Your original aggregate root would then not contain the child entities, but rather references to them (as they are now aggregate roots themselves - and links between aggregate roots should be via reference keys). This would help with your lazy loading strategy also. Hope that helps :)

Related questions

0 votes
    I have an Entity (QuoteSheet) that contains a child entity (QuoteTask), which is loaded using the ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 16, 2022 in Education by JackTerrance
0 votes
    Bit of a noob question but I'm building an app in react native and to make development a bit ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    As far as I've experienced JPA/hibernate will return entities that either exists at the database or have ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 18, 2022 in Education by JackTerrance
0 votes
    I'm using an abstract superclass for some React components that share methods and some (but not all) props ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 17, 2022 in Education by JackTerrance
0 votes
    I'm using an abstract superclass for some React components that share methods and some (but not all) props ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 14, 2022 in Education by JackTerrance
0 votes
    Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 21, 2022 in Education by JackTerrance
0 votes
    Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 21, 2022 in Education by JackTerrance
0 votes
    Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 20, 2022 in Education by JackTerrance
0 votes
    Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 20, 2022 in Education by JackTerrance
0 votes
    Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    I have a split screen design. I'd like to access the folder ID from the parent route only when ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 30, 2022 in Education by JackTerrance
0 votes
    I have a UITableView of customers where a row/customer is selected. The user can then push another view ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 26, 2022 in Education by JackTerrance
0 votes
    I have a UITableView of customers where a row/customer is selected. The user can then push another view ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 25, 2022 in Education by JackTerrance
0 votes
    I have a UITableView of customers where a row/customer is selected. The user can then push another view ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 25, 2022 in Education by JackTerrance
...