Edup
Repository Pattern and Clean Architecture
Whenever we perform a query, the ideal approach is to return only the necessary columns.
However, whenever I see content about repositories, the SELECT is always done using the entity. In other words, the entire entity is selected from the database.
In my projects, I create responses or DTOs. But DTOs are recommended in the application layer, while repository interfaces belong to the domain layer.
Of course, I could map the entity to a DTO to protect sensitive data.
However, I would still be loading all the data from the database, including many unnecessary fields.
For example, in an online store:
On the homepage, we only display promotional products with their price, title, and image. It doesn't make sense to fetch the entire product description from the database.
46 replies