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
- abstraction — A simplified description of what something does, such as an interface, that hides how it does it.
- Entity Framework Core — Microsoft's object-relational mapper for .NET, which lets code query and save database data as C# objects and translates LINQ into SQL.
- unit of work — A pattern that collects the changes made during one business operation and commits them together, or not at all.
- interface — A named set of member signatures that a type promises to implement, with no state of its own.
- ORM — A library that lets code read and write database rows as ordinary objects, generating the SQL for you.
- multi-tenancy — One running system serving several separate customers, called tenants, while keeping each one's data and settings apart.
- Spring Data JPA — A Spring project that generates repository implementations from interfaces, so declaring an interface is enough to get common database operations.
- layered architecture — Organising a system into ranked layers where each layer may only use layers below it.
- test double — Any object that replaces a real dependency in a test: a stub returns canned data, a fake is a small working implementation, and a mock checks interactions.
- generics — Types that take other types as parameters, so one definition works for many kinds of value.
- CRUD — Short for create, read, update and delete, the four basic things you can do to stored data.
- entity — A thing in an application's domain with its own identity, such as a user, account or product, usually stored in a database.
- implements — A class keyword that asks the compiler to check the class has everything an interface requires.
Taught in
- Classes, Interfaces, and Object-Oriented C# — Modern .NET Core, C# & Enterprise Microservices
- The Repository Pattern — Modern .NET Core, C# & Enterprise Microservices
- Unit Testing with xUnit and NSubstitute — Modern .NET Core, C# & Enterprise Microservices
- Database Access & Migrations: ORM & Data Layers — Production Full-Stack Engineering
- Multi-Tenant Identity: Tenant Isolation & Middleware — Production Full-Stack Engineering
- Asynchronous Event Processing: Outbox Pattern & Queues — Production Full-Stack Engineering
- The Cost Of Checked Exceptions — Modern Java: Virtual Threads & High-Throughput Services
- Designing Testable Code — Modern Java: Virtual Threads & High-Throughput Services
- Spring Data Repositories — Modern Java: Virtual Threads & High-Throughput Services
- Tying It All Together — Modern Java: Virtual Threads & High-Throughput Services
- Why Generics: Functions, Identities And Type Variables — Production TypeScript
- Const Type Parameters: Retaining Literal Types In Functions — Production TypeScript