Wednesday, November 30, 2016

Repository Pattern

A mediator between Data Access Layer (a Database, a SharePoint list, or a web service) and Business Logic Layer of the application. It has following benefits:
  • Centralises Data Access logic or Web Service Access logic.
  • Repository introduces an abstraction layer between the DAL and BL, which makes BL unit testable by mocking the repository, which was difficult before due to tight coupling between the DAL and BL.


Implementation Approach: Repository pattern can be implemented using two approaches:

  • One Repository per entity– each entity of the database will have its own repository.
  • Generic Repository – One generic repository which will be used by all the entities of the database. 
Lets take the same bank application example from previous post and introduce repository pattern in it. I have used the mix of above two approaches, where 

  • I create an abstract generic repository that has the common behaviours which all the database entities support.
  • I also create one repository (which inherits from generic repository created above) for each entity of database.

The next post is going to show the source code details of this example.

PS: Repository pattern can be used with or without the Unit of Work pattern. 


No comments:

Post a Comment