当前位置:网站首页>Realizing DDD based on ABP -- related concepts of DDD
Realizing DDD based on ABP -- related concepts of DDD
2022-07-26 17:01:00 【A Sheng 1990】
What is? DDD Well ? Domain-driven design [DDD] It is a software development method for complex requirements . Link software implementations to evolving models , Focus on core domain logic , Not the infrastructure details .DDD It is suitable for complex fields and large-scale applications , Not simply CRUD application . It helps to build a flexible 、 Modular and maintainable code base .
One .DDD Related concepts of domain layer and application layer in
DDD Mainly focus on domain layer and application layer .
1.DDD The domain layer in
The basic concepts in the domain layer are :
(1) Entity [Entity]
Entities are like objects in object-oriented , It contains properties and methods , And there's only one ID.
(2) The value object [Value Object]
Value objects are domain objects of types in the domain . It sounds abstract , For example, I see . such as , Order Order This aggregation root consists of a series of attributes : Unique identification ID、OrderDate、OrderItems、Address etc. . among Address It's a value object . The value object = value + object = Express a value as an object , To express a specific fixed concept .
(3) polymerization [Aggregate] And aggregate roots [Aggregate Root]
⼀ An aggregate is a series of objects [ Entities and value objects ] Set , Bind all associated objects to... Through the aggregation root ⼀ rise . such as ,Issue Aggregation is by Issue[ Aggregate root ]、Comment[ Entity ] and IssuelLabel[ The value object ] Set of components .
(4) Storage [Repository]
The warehousing interface is defined at the domain level , Implemented at the infrastructure level . Why storage ? The main thing is to decouple the database , Decouple database operations such as adding, deleting, checking and modifying from different types of databases .DDD One of the general principles is the principle of database independence , The domain layer and application layer only depend on the warehousing interface , And the storage interface is not suitable for any ORM Special objects .
(5) Field service [Domain Service]
Domain services encapsulate the core business logic , It combines and encapsulates one or more methods of the same entity , Or to combine or arrange the operations of multiple different entities , External exposure into the field of service .
(6) Statute [Specification]
The statute is ⼀ Named 、 Heavyweight ⽤ Of 、 Composable and testable classes ,⽤ To filter domain objects according to business rules .
(7) Field events [Domain Event]
Through message queuing , such as RabbitMQ etc. , When a specific domain event occurs , Other services will be notified .
2.DDD Application layer in
The basic concepts in the application layer are :
(1) Application service [Application Service]
Usually, the input and output of the application service layer are DTO, And an application service is usually considered a transaction .
(2) Data transmission object [DTO]
The main purpose is to decouple the application service layer and the presentation layer . without DTO, Then the application service layer returns the complete object , Contains fields that are not required by the presentation layer , And it may also disclose the object field information .
(3) The unit of work [Unit Of Work]
The simple understanding is that it is either all successful , All or nothing .
Two . be based on ABP The solution structure created by the template
be based on ABP The solution structure created by the template is as follows :
1. Domain layer
(1)IssueTracking.Domain[ Domain layer ]: that item ⽬ Include entity 、 The value object 、 Field service 、 Statute 、 Warehouse connection ⼝ etc. .
(2)IssueTracking.Domain.Shared[ Domain sharing layer ]: Commonly defined constants and enumerations , All in this item ⽬ in .
2. application layer
(1)IssueTracking.Application.Contracts[ Application contract layer ]: It contains application service interface and data transmission object . that item ⽬ Be answered ⽤ Program client reference , such as Web project 、API Client project .
(2)IssueTracking.Application[ application layer ]: Realize in Contracts The connection defined in the project ⼝.
3. Presentation layer
(1)IssueTracking.Web[ Presentation layer ]: This is the project naming method that does not separate the front end and the back end , Then it is usually a ASP.NET Core MVC/Razor Pages application .
explain : If it's a front-end separated project , The project will not be included in the solution , But through IssueTracking.HttpApi.Host Project provides HTTP API service , For the client to call .
4. The remote service layer
(1)IssueTracking.HttpApi[ The remote service layer ]: Simple understanding is a very thin control layer , This item is mainly used to define HTTP API, That is, the wrapper of the application service layer , Expose them to remote client calls .
(2)IssueTracking.HttpApi.Client[ Remote service agent layer ]: When a third-party client references the project , You can use remote service applications directly through dependency injection , Based on ABP The dynamics of the C# client API Agent system .
5. Base layer
(1)IssueTracking.EntityFrameworkCore:EF Core The core foundation depends on the project , Contains the data context 、 Database mapping 、EF Core Warehouse implementation, etc .
(2)IssueTracking.EntityFrameworkCore.DbMigrations: Used to manage Code First A special tool project for data migration . newest ABP This item has been removed in , Don't understand .
6. Other layers
(1)IssueTracking.DbMigrator: Console Application , It mainly migrates the database structure and initializes the seed data .
3、 ... and . Project dependencies in the solution
The dependencies between projects in this solution are as follows :
1.Domain.Shared
All projects depend directly or indirectly on this project , All types in this project can be referenced by other projects
2.Domain
Rely only on Domain.Shared project .
3.Application.Contracts
rely on Domain.Shared project , Can be in DTO Medium multiplexing Domain.Shared The type of .
4.Application
rely on Application.Contracts project , Because this project needs to implement the interface of application services and the interface used DTO. In addition, it also depends on Domain project , Because warehouse interfaces or domain objects are used in application services .
5.EntityFrameworkCore
rely on Domain project , Because this project requires domain objects [ Entity or value object ] Tables mapped to the database , In addition, we need to realize Domain Warehousing interface in the project .
6.HttpApi
rely on Application.Contracts project , because Controllers Need to inject application service interface .
7.HttpApi.Client
rely on Application.Contracts project , Because this project needs to use the application service interface .
8.Web
rely on HttpApi project , Publish defined HTTP API. In addition, it also indirectly depends on Application.Contracts project , It can be found on the page / Using application services in components .
Look at the dotted line of the solution dependency diagram above , You will find Web The project depends on Application and EntityFrameworkCore project . This is because Web Is a deployable project , In the application, the implementation of application services and warehousing is required . One drawback of this framework design is that entities and EF Core Object's , But this is strictly avoided .
Four .DDD Application execution process

The first 1 Step : Whether in the browser Web Application, Or remote client , They initiate HTTP Request to server .
The first 2 Step :MVC UI perhaps HTTP API Receive and process requests , At this stage AOP Logic , Such as authorization 、 Input validation 、 exception handling 、 The audit log 、 Cache, etc .MVC Controller Inject the application service interface into the constructor , Call methods to send and receive DTO object .
The first 3 Step : Application services use domain level objects [ Entity 、 Warehouse interface 、 Domain services, etc ] To implement use cases , At this stage, also perform some AOP Logic , Such as authorization 、 verification 、 Audit logs and work units . An application service approach is a unit of work , It's atomic .
reference :
[1]abp-vnext-pro:https://github.com/WangJunZzz/abp-vnext-pro
[2]iEricLee Of ABP Blog :https://www.cnblogs.com/YGYH/
[3]cms-kit:https://github.com/abpframework/abp/tree/dev/modules/cms-kit
[4] be based on ABP Framework Implement domain-driven design :https://url39.ctfile.com/f/2501739-616007877-f3e258?p=2096 ( Access password : 2096)
边栏推荐
- Tcpdump命令详解
- 【飞控开发基础教程1】疯壳·开源编队无人机-GPIO(LED 航情灯、信号灯控制)
- Marketing guide | several common micro blog marketing methods
- C#转整型的三种方式的区别以及效率对比
- 【飞控开发基础教程2】疯壳·开源编队无人机-定时器(LED 航情灯、指示灯闪烁)
- 京东三面:我要查询千万级数据量的表,怎么操作?
- [development tutorial 8] crazy shell · open source Bluetooth heart rate waterproof sports Bracelet - triaxial meter pace
- 第一章概述-------第一节--1.3互联网的组成
- Singleton mode
- kubernetes之ConfigMap
猜你喜欢

C#事件和委托的区别

Differences between the use of structs and classes

NUC 11 build esxi 7.0.3f install network card driver-v2 (upgraded version in July 2022)

【Flutter -- 进阶】打包

Tcpdump命令详解

"Green is better than blue". Why is TPC the last white lotus to earn interest with money
![[development tutorial 8] crazy shell · open source Bluetooth heart rate waterproof sports Bracelet - triaxial meter pace](/img/92/91cbc9dad67bb23276386dcbb82f1c.png)
[development tutorial 8] crazy shell · open source Bluetooth heart rate waterproof sports Bracelet - triaxial meter pace
![[ctfshow-web]反序列化](/img/cd/b76e148adfc4d61049ab2cf429d4d7.png)
[ctfshow-web]反序列化

Idea Alibaba cloud multi module deployment

37.【重载运算符的类别】
随机推荐
Using MySQL master-slave replication delay to save erroneously deleted data
On the evolution of cloud native edge computing framework
[development tutorial 8] crazy shell · open source Bluetooth heart rate waterproof sports Bracelet - triaxial meter pace
Oracle创建表分区后,查询的时候不给出partition,但是会给分区字段指定的值,会不会自动按照分区查询?
My SQL is OK. Why is it still so slow? MySQL locking rules
IDEA 阿里云多模块部署
movable-view 组件(可上下左右拖动 )
Win11如何关闭共享文件夹
UPC 2022 summer personal training game 07 (part)
别用Xshell了,试试这个更现代的终端连接工具
Alibaba side: analysis of ten classic interview questions
6种方法帮你搞定SimpleDateFormat类不是线程安全的问题
JD Sanmian: I want to query a table with tens of millions of data. How can I operate it?
广东首例!广州一公司未履行数据安全保护义务被警方处罚
Can TCP and UDP use the same port?
Response object - response character data
[basic course of flight control development 2] crazy shell · open source formation UAV - timer (LED flight information light and indicator light flash)
srec_ Use of common cat parameters
What is the complexity often said during the interview?
Singleton mode