Do you use the repository pattern for data access?

Last updated by TiagoAraujo over 4 years ago.See history

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

We open source. Powered by GitHub