I. Basic knowledge preparation:
1. Layer principle:
(1) Each layer is called by the upper layer in an interface manner.
(2) The upper layer can only call the lower layer.
(3) Dependence is divided into two types:loose interaction and strict interaction.
2. Business logic classification:
(1) Application logic.
(2) Domain logic.
3. Layers used:
(1) presentation layer (user interface layer):domain-independent.
(2) Service layer (application layer):application logic.
(3) Business logic layer (domain layer):domain logic.
(4) shared layer:provide common code.
(5) Implementation layer:Provides interface implementation.
(1) The domain layer adopts the domain model by default
(2) The data access layer needs to reference the domain model by default
The three basic levels of the hierarchical architecture are:the presentation layer, the business logic layer, and the data access layer.If the business logic layer is decomposed into a service layer and a domain layer according to the classification of the business logic,Then the three layers are expanded into four layers:the presentation layer, the service layer, the domain layer, and the data access layer.The data access layer must generally understand the domain model,This will create a two-way dependency between the layers,Generally we have the following two solutions:
1. Place the domain model in the shared layer:
Evaluation:petshop uses this model,But there are many disadvantages:the name of the business logic layer is not true,The domain model is really a data model.Maintaining inter-layer dependencies,Introduced more dependencies,Obvious data-driven thinking,There is no realm at the core.
2. Define the data access interface at the business logic layer:
Evaluation:nopcommerce uses this model,Even if the service layer is separated and the resource library is named,But nopcommerce is not a ddd layered architecture,It's just a common three-tier architecture that uses the principle of domain model and interface separation.Cons:In addition to data property,No other specific technical dependencies are separated from the business logic layer.
Ddd hierarchically clearly divides the business logic layer into an application layer (service layer) and a domain layer.At the same time, the specific technical implementation parts of data access and other interfaces are unified to the infrastructure layer.
1. Original ddd layering:
Evaluation:The advantage is that the specific technology is separated from the field.Infrastructure layer reuse value increases.The disadvantage is that the infrastructure layer is not broken down using the concepts of sharing and implementation,Leading to the realization of warehousing in the infrastructure layer will generate reverse dependencies,Although there is no impact in single-project solutions (only the formal dependencies of the namespace hierarchy), in .net multi-project solutions,The warehousing can only be separated into a similar data access layer through interface separation.
2. Improved ddd layering:
Evaluation:The infrastructure layer has the characteristics of both a sharing layer and an implementation layer.The advantage is that it finally achieves the formal domain as the core and at the same time solves the embarrassment that the warehouse model cannot be referenced in the infrastructure layer.The disadvantage is that there is also no distinction between sharing and implementation.
3.Latest ddd layering:
Evaluation:The advantage is that this is truly domain-centric,There is no longer a need to adapt the infrastructure layer to the domain layer and not the service layer.Use the dependency inversion principle to completely invert the dependence of each layer on a specific technology.Disadvantages, relying too much on inverted applications,There is also no problem in single-project solutions,But in the .net multi-project solution will lead to a two-way dependency on the form of the namespace.The infrastructure layer as the implementation layer basically has no value for reuse.A better way is to swap the positions of the user interface layer and the infrastructure layer in the diagram.
You can consider adding an appropriate sharing layer to the above picture as needed.
Four. Architecture trends:
(1) With business logic as the core,Pay more attention to business logic.
(2) The specific dependencies of the business logic layer are divided into a unified management layer.
(3) Pay more attention to reducing dependencies within solutions rather than code reuse between solutions.
(4) The separation between the sharing layer and the implementation layer will be more and more manifested.For example onion-type architecture.
- python - you may need to restart the kernel to use updated packages error
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- python 3x - typeerror: 'method' object is not subscriptable
- i want to call a child component method from a parent in vuejs
- xcode - pod install [!] no `podfile 'found in the project directory
- dart - flutter: the instance member'stars' can't be accessed in an initializer error