What we supposedly use the Repository pattern for?
- For querying the model?
- For CRUD operations?
- To have work with entities like they were already loaded in memory?
- To not depend on underlying technologies like ORMs?
Pure junk! All those arguments could live in the 2000s, but they are now absolutely outdated!!
I’m done with that pattern. It doesn’t offer a **** and instead of this, it just adds complexity and a bunch of classes and interfaces that restrict your queries to a poor set. It’s OK that you can write your own methods in a custom repository, but as you do, it loses its maintainability and it can really get riddled with tenths of methods for each kind of query you want to get (and this really gets worse when you have to retrieve lots of different DTOs).
So, forget about this pattern if you’re getting data access seriously and start researching on new ways to do MORE, not the same or less.
Use an ORM! and don’t wrap it! if you do, you’re losing your precious time. Do you think that a change in the Database will not affect you if you wrap, and wrap, and wrap it again? HA! In the best of cases you will end up having to design 200 DTOs and 1000 different methods to access the database in a “decoupled” way.
So if you try to make an onion, good luck!