repository pattern

Putting all the code that reads and writes one kind of data behind a single object, so the rest of the app never talks to the database directly.

In more detail

Application code calls methods such as orders.create() instead of writing queries, which keeps business logic clean and makes storage easy to swap or replace with an in-memory version in tests. If a repository only renames an ORM's own methods, it adds ceremony without a real boundary.

Examples

EF Core's DbContext already is a repository and unit of work, so wrap it only when that adds meaning.
OrderRepository: orders.findById(id) with no SQL in the service.

Related terms

Taught in

References