views:

175

answers:

3

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?

+6  A: 

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.

Brandon Satrom
You can never go wrong with 'it depends'. :)
Arnis L.
+1  A: 

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.

Al Bundy
+1  A: 

The one reason we use Repositories in our project is that it enforces who our Aggregate Roots are (we only allow repositories for ARs) so that you work through the AR properly instead of querying for whatever strikes your fancy.

And as Al mentioned.. it does provide a nice interface to mock out during unit tests.

ShaneC