- Mastering Microservices with Java 9(Second Edition)
- Sourabh Sharma
- 356字
- 2021-07-02 21:54:50
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 file system. 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 the 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 is 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 requestor does not need to interact directly with the 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:

Repository object flow
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 requestor may belong to a domain layer, or an application layer. The repository helps the system to manage the life cycle of domain objects.
- Mastering ServiceStack
- ReSharper Essentials
- Scratch 3.0少兒編程與邏輯思維訓(xùn)練
- RabbitMQ Cookbook
- Extending Puppet(Second Edition)
- Raspberry Pi Home Automation with Arduino(Second Edition)
- Instant Debian:Build a Web Server
- Oracle數(shù)據(jù)庫(kù)編程經(jīng)典300例
- 計(jì)算機(jī)應(yīng)用技能實(shí)訓(xùn)教程
- 從零學(xué)Java設(shè)計(jì)模式
- 計(jì)算機(jī)系統(tǒng)解密:從理解計(jì)算機(jī)到編寫高效代碼
- Hadoop Blueprints
- 樹莓派開發(fā)從零開始學(xué):超好玩的智能小硬件制作書
- Java Web程序員面試筆試寶典
- 活文檔:與代碼共同演進(jìn)