Can an entity make use of dependency injection #961
Answered
by
renetitulaer
renetitulaer
asked this question in
Q&A
-
Let's assume I want to run a query from one entity for data which lives in another aggregate. How would that look like? |
Beta Was this translation helpful? Give feedback.
Answered by
renetitulaer
Aug 27, 2025
Replies: 1 comment 4 replies
-
Why would you run a query from an entity? What's the actual use case? |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks @KyleMcMaster.
My conclusion is that domain service is the way to go.
The events/mediatr alternatives feels like sneaking in dependencies. I also agree about the argument of violating the Explicit Dependencies Principle.
What is weird in the examples is that there is a product and a catalog and that the catalog is marked as an aggregate while it's only a collection of products. An aggregate should have an id and catalog does not have an id. So catalog is not an entity at all.
I do think it makes sense to distinguish the entity and the collection. The entity should encapsulate the rules of the entity. Entity does not have dependencies. The collection will be used in the domain servi…