官术网_书友最值得收藏!

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:

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 requester may belong to a domain layer, or an application layer. The repository helps the system to manage the life cycle of domain objects.

主站蜘蛛池模板: 宣化县| 永安市| 鄄城县| 郴州市| 巴彦淖尔市| 赤水市| 平昌县| 泗水县| 玛多县| 阳东县| 偏关县| 桐梓县| 和政县| 舒兰市| 西安市| 虎林市| 剑川县| 嘉定区| 永川市| 香河县| 东至县| 祁门县| 北流市| 渭源县| 灯塔市| 江永县| 宣恩县| 鹤壁市| 东乡县| 西盟| 隆化县| 石景山区| 和林格尔县| 乌拉特前旗| 陇南市| 宝兴县| 平顶山市| 东兴市| 社旗县| 大同县| 龙州县|