I’m starting to hate the Repository pattern

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!


4 thoughts on “I’m starting to hate the Repository pattern

    1. Súper JMN

      Hi Unai. Thanks for your comment. I remember reading your post in the past 🙂

      I see both points.
      Well, I admit I supported the usage of a “wrapping” implementation of the Repository pattern. I liked to think I only depend on my own light interfaces with the lowest coupling to any underlying ORM/DAL or any other method of accessing the data.
      I soon discovery that my additional layers offered little to no advantages over the DbContexts that I tried to wrap. In fact, I was making a really high effort to build all the required methods, DTOs and mappings that my repositories required.
      Gradually, I started to switch to a more pragmatic way of doing things: IF IT’S WELL DESIGNED, DON’T WRAP IT!
      Why should I wrap already clean interfaces? Why do some people think a LINQ query is damaging the quality of the design or the encapsulation or the SRP principle?
      Most of times you end up doing basic queries that are easily changed (if needed!). So, yes, I use zero protection over the ORM if it’s well designed.
      Even more, the Repository pattern for me is totally obsolete. It fails provide the so called in-memory representation of the model. If you wan to keep it simple, it’s a silly endpoint. If you want to make it powerful and extensible, you eventually will get something like a DbContext.

      What do you think? Are you still thinking the same 🙂

      Best regards.



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s