I'm working in this scenario
Post entity has many Image entities.
I also have repository to both entities:
Since this entities are tightly related, when I get a Post I want to return the list of images also.
I have to possible ways of do this:
The orchestator (in this case a PostService) will call indepently each one of the Repositories to fecth the data. PROs:
- For sure don't violates SRP CONs:
- Create extra dependencies PostService might not have need to have a dependency with ImageRepository.
- Unnecesary calls to database
The PostRepository will return the whole Graph Post with Images PROs:
- Reduce dependencies
- Simplify the database query. CONs:
- Might violate SRP.
In the case of a writting scenario I clearly prefer the 1st option, since I want to keep validation of entities completely segreggated. But for reading scenario I thinkg 2nd option could be more optimal, however I couldn't find any good argument or reading for this.
So which option is better for the reading scenario?