Generic Repository and Leaky Abstraction

Viewed 1292

I am implementing a repository pattern. My main reasons for this:

  • To abstract client code away from persistence specifics (Entity Framework)
  • To support testability

Generic Repository or not?

The issue I have run into is whether I should have a generic repository or not. An IQueryable<T> Query() method would provide the calling code with means to construct specific queries. The issue here is that this is leaky abstraction - Entity Framework specifics are now leaking into my client code.

enter image description here

  • How would this effect unit testing? Would I still be able to Mock the ICustomerRepository with this implementation?

  • How would this effect swopping out my persistence layer? Like Azure Storage Tables or NHibernate.

Otherwise I would have to implement very specific query method on ICustomerRepository, such as GetIsActiveByFirstName() and GetIsActiveByDistrict(). I dislike this a lot as my repository classes are going to become jam-packed with different query methods. This system has hundreds of models and so there could be hundreds or even thousands of these methods to write and maintain.

1 Answers
Related