"Enterprise Application Systems" have complex business, and a relatively long lifecycle, in which business rules will change frequently and the technology used may change. In order to better extend and maintain this kind of system later, we can choose the domain-oriented multi-layer architecture, reduce the coupling between the components, the layer and the layer, so that we can lock the change to the domain layer whenever the business logic changes or new business expansion, so as to minimize the impact on the other layers.
Domain-driven architectures are typically divided into four tiers: presentation, application, domain, and infrastructure.
Presentation Layer (Presentation)
The primary responsibility of this layer is to display the data information to the user through the user interface, while interpreting the user's commands and sending the user's request to the application layer.
Application Layer (application)
The application layer is primarily used to coordinate actions between different domain objects or between domain models and infrastructure layer components to accomplish a specific, clear system task.
One requirement is to send an email to the user after an order is saved. The save order is business, the business code is in the domain layer, and the email is the infrastructure layer, then you need to use the application layer to coordinate the actions between the domain object and the infrastructure object.
Domain model layer (domain models)
The high level of business logic to the domain layer, so the domain layer is the core of the entire system, it is only relevant to the actual business, should not be concerned about any technical details, as far as possible to do with the persistence of irrelevant.
Entities are important in the domain model, and objects that are distinguished by identities are called entities (that is, identities must be unique).
Unlike entities, value objects are not identified, do not need to track the state of Value objects, and value objects are very easy to create and discard. Value objects are immutable, created with a constructor, and all properties are defined as read-only. If one of the properties needs to be modified, a new value object needs to be recreated to replace the whole. The equality comparison of a value object is accomplished by comparing the values of each property.
When designing a domain model, some business behaviors do not fit in any one domain object, or the business behavior needs to federate multiple domain entities to complete, then we put it in the corresponding domain service. Domain-level services are responsible for interacting with entity objects, value objects, and other domain-level objects in the domain.
Aggregations typically define a set of associated objects, as well as the boundaries between objects and relationships, as a unit of data change processing. Each aggregation has only one aggregate root (Entity object). An aggregate root can reference other aggregate roots, and an object within an aggregation can reference another object within the aggregation, but any object outside the aggregation boundary cannot bypass the aggregate root object to access the objects within the aggregation.
Create a repository for each aggregate root object that represents all objects of that type as a collection of conceptual objects, access to the repository through a similar set of interfaces. The point of warehousing is to let developers focus on the domain model logic and hide real data access behind the warehousing interface, which is not the domain model that was previously said to be persistent.
Many times, it is complicated to construct an aggregation with all its relationships, constraints, rules, and so on, so that the creation of an entity object's own responsibility for the object will make the code confusing. At this point, you need to have a factory that knows how to build these types of objects and create them uniformly.
Infrastructure Layer (Infrastructure)
The infrastructure layer contains any type of framework, data access code, or public help methods, and is a layer of pure technology.
Domain driven Design (i) Understanding hierarchical architecture