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 pensamientos en “I’m starting to hate the Repository pattern

    • 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.

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s