- Mastering Microservices with Java
- Sourabh Sharma
- 355字
- 2021-07-02 13:03:37
Repository
In a domain model, at a given point in time, many domain objects may exist. Each object may have its own life cycle, from the creation of objects to their removal or persistence. Whenever any domain operation needs a domain object, it should retrieve the reference of the requested object efficiently. It would be very difficult if you didn't maintain all of the available domain objects in a central object. A central object carries the references of all the objects, and is responsible for returning the requested object reference. This central object is known as the repository.
The repository is a point that interacts with infrastructures such as the database or filesystem. A repository object is the part of the domain model that interacts with storage such as the database, external sources, and so on, to retrieve persisted objects. When a request is received by the repository for an object's reference, it returns the existing object's reference. If the requested object does not exist in the repository, then it retrieves the object from storage. For example, if you need a customer, you would query the repository object to provide the customer with ID 31. The repository would provide the requested customer object if it was already available in the repository, and if not, it would query the persisted stores, such as the database, fetch it, and provide its reference.
The main advantage of using the repository is having a consistent way to retrieve objects where the requester does not need to interact directly with storage such as the database.
A repository may query objects from various storage types, such as one or more databases, filesystems, or factory repositories, and so on. In such cases, a repository may have strategies that also point to different sources for different object types or categories:

As shown in the repository object flow diagram, the repository interacts with the infrastructure layer, and this interface is part of the domain layer. The requester may belong to a domain layer, or an application layer. The repository helps the system to manage the life cycle of domain objects.
- Python for Secret Agents:Volume II
- Vue.js前端開發(fā)基礎(chǔ)與項目實戰(zhàn)
- AIRAndroid應(yīng)用開發(fā)實戰(zhàn)
- Getting Started with PowerShell
- Learning Elixir
- MATLAB實用教程
- 手把手教你學(xué)C語言
- Python漫游數(shù)學(xué)王國:高等數(shù)學(xué)、線性代數(shù)、數(shù)理統(tǒng)計及運籌學(xué)
- Python完全自學(xué)教程
- 表哥的Access入門:以Excel視角快速學(xué)習(xí)數(shù)據(jù)庫開發(fā)(第2版)
- 智能搜索和推薦系統(tǒng):原理、算法與應(yīng)用
- Kotlin開發(fā)教程(全2冊)
- Android群英傳
- Java Web從入門到精通(第3版)
- Android Development Tools for Eclipse