Home
Do you use the repository pattern for data access?
  v6.0 Posted at 30/07/2019 10:35 AM by Tiago Araujo

The repository pattern is a great way to handle your data access layer and should be used wherever you have a need to retrieve data and turn it into domain objects.

The advantages of using a repository pattern are:

  • Abstraction away from the detail of how objects are retrieved and saved
  • Domain objects are ignorant of persistence - persistence is handled completely by the repository
  • Testability of your code without having to hit the database (you can just mock the repository)
  • Reusability of data access code without having to worry about consistency

Even better, by providing a consistent repository base class, you can get all your CRUD operations while avoiding any plumbing code.

Tip: Entity Framework provides a great abstraction for data access out of the box. See Jason’s Clean Architecture with ASP.NET Core talk ​for more information​

Related rules

    Do you feel this rule needs an update?

    If you want to be notified when this rule is updated, please enter your email address:

    Comments: