I have been using Repository pattern (DDD and POEAA) for some time. However some of our team members have argued that it is just an extra layer of abstraction and unnecessary. I can seen some benefit in their arguments. Modern ORM solutions (NHibernate or EF) have almost everything you need. I searched and found some article like this and counterargument on this topic. So Is repository pattern an overkill?
The Repository pattern makes it easier to test your application logic. The Repository pattern allows you to easily test your application with unit tests. Remember that unit tests only test your code, not infrastructure, so the repository abstractions make it easier to achieve that goal.
The Repository Pattern is used to simplify the Application Layer and is defined by the Application Layer . The repositories evolve with the Business Use Cases . The Repository handles domain objects and is agnostic of the technical details. Generics can still be used to implement the repositories.
The benefit of using The Repository Pattern in this instance is that you can write the Repository interface at the beginning of the project without really thinking about the actual technical details of how you are going to store your data.
A key benefit of the Repository pattern is that it allows us to use the Principle of Dependency Inversion (or code to abstractions, not concretions). This makes our code more robust to changes, such as if a decision was made later on to switch to a data source that isn't supported by Eloquent.
It depends, mostly on the complexity of your problem and the role your Domain Model plays in the solution. For simple solutions, Repository is probably overkill. But for complex domains with a robust language and evolving needs/requirements, the Repository is a nice, clean abstraction that owns the domain object lifecycle. Many ORMs will do much of this, but, in a complex domain, there will always be some domain activity that makes sense in a repository and which is not supported by an ORM out of the box.
Bottom line: it depends on the context.
Mocking data access in unit tests is the main reason I use repository interfaces. Another reason maintainability - you can easily implement caching strategies, or switch to other data access implementation, like getting data from the service instead of DB.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With