DDD noob here. Say we have a domain aggregate for Orders (e.g. MS DDD Article). Using this example, we want to query all orders that contain a particular item. Further, we are not really interested in all that is in the order or item. Just the orderId, date, and item name suffice for displaying back to user/responding to API. Struggling with the following:
- Does the repository (which returns domain objects) return full (i.e all properties) matching orders and all their items and then subsequently a domain object/service has to filter for non-interested items? Seems very inefficient and not taking advantage of our persistence (SQL) engine capabilities to narrow a search. Also this subsequent filtering will change the behavior of the domain object (e.g. state of the order and its total) which may cause side effects if this order's data/behavior is used by the caller.
- Or does the repository return a DTO of sorts that only has the data properties we need for the caller? This seems efficient, except over time this list of DTOs can grow to be hundreds of classes that satisfy some niche requirement in the system. Seems ugly.
Are these concerns valid and/or is there a better way ?