Repository pattern
The repository pattern is a software design pattern that abstracts access to and persistence of application or domain data, hiding storage-specific operations.
Spring in Action, Sixth Edition
A repository interface is an interface that declares data-access operations for an entity while leaving their persistence implementation to a supporting framework.
- How it is used
- Separates ingredient and order data access from controllers while supporting persistence across relational and nonrelational databases.
- How deep it goes
- Works through handwritten JdbcTemplate operations and generated Spring Data interfaces, including entity and ID types.
- Examples
- Uses ingredient lookup and saving, order persistence, controller injection, and repository declarations for several database types.
- What you can do after
- Apply it via Spring Data by declaring CrudRepository interfaces for entities and injecting them into controllers.
Read how Spring in Action, Sixth Edition explains repository pattern →
Learn Go with Pocket-Sized Projects
The repository pattern is an abstraction that mediates between an application’s domain model and persistent data storage.
- How it is used
- Separates game and habit storage from API handlers and domain logic.
- How deep it goes
- Works through an in-memory map, constructor, operations, injection, tests, and concurrency; defers database implementation.
- Examples
- Uses stored games, a stubbed game-creation handler, and a sorted list of saved habits.
- What you can do after
- Build it from scratch as an injectable in-memory repository, then test its operations and protect shared state.
Read how Learn Go with Pocket-Sized Projects explains repository pattern →
Unit Testing Principles, Practices, and Patterns
A repository is an abstraction that provides access to and modification of persisted data for a particular domain object or aggregate.
- How it is used
- Separates domain-specific database access from transaction decisions during business operations.
- How deep it goes
- Defines responsibilities, lifespans, transaction enlistment, testing trade-offs, and a repository refactoring, but not database internals.
- Examples
- Uses UserRepository, CompanyRepository, CrmContext, a user email change, and an integration test sharing context.
- What you can do after
- Apply it via focused repositories and shared transactions, then evaluate repository tests by maintenance cost and regression value.
Read how Unit Testing Principles, Practices, and Patterns explains repository pattern →
Quarkus in Action
The repository pattern encapsulates data-access operations behind an abstraction that manages persistence and retrieval for domain objects.
- How it is used
- Replaces an inventory stub with a database-access object used by GraphQL and gRPC services.
- How deep it goes
- Builds a MySQL-backed repository from extensions and a JPA entity through a custom lookup, service calls, and transaction handling.
- Examples
- Uses a car inventory, a license-plate lookup, GraphQL and gRPC operations, and an SQL seed script.
- What you can do after
- Apply it via Panache to persist, list, find, and delete inventory entities through a repository.
Pro Angular 16
A repository is an abstraction that mediates access to data while hiding how that data is obtained from application components.
- How it is used
- Mediates application access to product data while hiding whether a data source supplies records statically or through a REST request.
- How deep it goes
- Builds product repositories with lookup and change operations, then elaborates signal exposure, computed categories, and asynchronous loading.
- Examples
- Uses product arrays, an ID lookup, derived categories, a product-count computation, and a REST-backed replacement for static data.
- What you can do after
- Build it from scratch with product operations and controlled signal access, then connect it to a static or REST data source.
.NET in Action, Second Edition
The repository pattern is an architectural pattern that encapsulates access to and persistence of domain entities through a collection-like interface between the domain model and data-mapping or persistence layers.
- How it is used
- Abstracts data-store access to separate domain logic from persistence and support unit testing.
- How deep it goes
- Defines the collection-like role and demonstrates repository interfaces in an importer, without detailing persistence implementation.
- Examples
- Uses a CSV customer importer and an XKCD comic repository for unit and integration testing.
- What you can do after
- Apply it via repository interfaces to substitute fake data stores in unit tests without setting up test databases.
Read how .NET in Action, Second Edition explains repository pattern →
AI-Powered Developer: Build software with ChatGPT and Copilot
The Repository Pattern is a software design pattern that encapsulates data-access operations behind an interface separate from application logic.
- How it is used
- Separates asset data access from application services while preserving a consistent CRUD interface.
- How deep it goes
- Explains the abstraction, generic contract, in-memory implementation, service delegation, and database-backed replacement.
- Examples
- Uses BaseRepository, InMemoryAssetRepository, AssetManager, SQLAlchemyAssetRepository, and application wiring as concrete examples.
- What you can do after
- Build it from scratch by defining a repository contract, implementing storage adapters, and switching implementations through application wiring.
Read how AI-Powered Developer: Build software with ChatGPT and Copilot explains repository pattern →
Effective Platform Engineering
A repository layer is an architectural layer that exposes datastore operations through repository abstractions to higher layers.
- How it is used
- Supports service development by standardizing datastore access and reducing dependence on cloud-specific technologies.
- How deep it goes
- Explains the layer arrangement, interface boundary, migration effect, and automated architectural checks, without detailing repository method implementations.
- Examples
- Uses GCP migration, AWS RDS for PostgreSQL, Aurora Serverless for MySQL, relational and unstructured datastores, and layered pseudocode.
- What you can do after
- Apply it via repository and datastore interfaces to change supported databases or clouds while minimizing service rewrites.
Read how Effective Platform Engineering explains repository pattern →
Simple Object-Oriented Design: Create clean, maintainable applications
A repository is a component that encapsulates the logic for retrieving and persisting domain information.
- How it is used
- Separates domain data-access behavior from infrastructure and persistence implementation details.
- How deep it goes
- Defines repository responsibilities and demonstrates interface replacement, but defers the detailed challenges of implementing caching.
- Examples
- Uses EmployeeRepository, HibernateEmployeeRepository, findById, findByLastName, save, Hibernate, Postgres, and a cache.
- What you can do after
- Apply it via a repository interface that allows persistence implementations and infrastructure optimizations to change independently.
Related concepts
- Spring Data RESTused by · Spring Data REST is a Spring Data project that exposes repository-backed data and operations through RESTful resources.
- databaseuses · A database is an organized collection of persistent data managed by software for storage, retrieval, querying, and modification.
- active record patternalternative to · The Active Record pattern combines an object representing a persistent data record with operations for querying, storing, updating, and deleting that record.
- methodhas part · A method is a callable operation associated with an object or type and invoked through that association.
- domain modelcontrasts with · A domain model is a software representation of the concepts, entities, relationships, rules, and behavior of a problem or business domain.
- database transactionuses · A database transaction is a logical unit of database operations whose changes are committed together or rolled back as a whole.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.








