Until this moment, I have seen a lot of variations and combinations of the Repository pattern, implementations that simply queried the required information, some used something like a mapper, some used something called Units of Work, and some used something called CQRS that separated the reads from the writes, updates and deletes.
A common thing was that the interface of the repository was defined in the domain/entity layer of the application and implemented in the persistence layer, BUT…
There are some things I couldn’t get my head around, because almost if not all of these tutorials / articles I’ve read on this topic, involved the using of a framework or something that I wasn’t familiar with.
I’m aware that the example is stupid simple and in a real life scenario it will be an overkill to use this, or perhaps any pattern, but I’ll try to keep this short not to waste anyone’s time with complex examples that could lead to ambiguity and interpretation. I’m also aware of the fact that the answer depends on the complexity of the domain problem; we are talking general here. Another thing is that we are doing a DDD-style implementation, so you should make some assumptions about the architecture of this application based on DDD.
So with that said let’s imagine a simple application with an layered-architecture, perhaps an simple API that lists the products inside an warehouse for example, let’s say we have an Item entity with its corresponding Value Objects (like ID, Name, Description), the point of this API is that it lists the items along with the attributes in maybe a JSON format and it provides a way to select specific data depending on some filters/conditions.
With that out of the way the questions:
Imagine we have an “ IItemRepo ” interface implemented by the Persistence mechanism.
Where this object will be instantiated?
Who will have knowledge of this object?
How the information that it provides will end up be used by the
Domain/Application layer? Factories, but how exactly?
Will this object be passed around from layer to layer? Aren’t DTO’s
the only objects allowed this kind of behavior?
There may be also other questions based on your answers.