Skip to content

Commit b8720dc

Browse files
committed
add layer
1 parent c211f08 commit b8720dc

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

backend/Java后台服务分层规范.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99

1010
![分层示例](./resources/java_project_layer.png)
1111

12+
其中各层的引用关系从上到下依次为:
13+
API层 -> Application层 -> DomainService -> Repository -> DomainModel
14+
15+
引用关系见下图
16+
![分层示例](./resources/java_layer_depencies.png)
17+
1218
## 2. API层
1319

1420
API层用来定义对外的接口,对应于SpringMVC的Controller。
@@ -67,4 +73,12 @@ utility层包含一些共用的辅助方法。
6773

6874
- 对于比较复杂的项目,每个分层中可以根据模块再分成多个目录,以方便管理。
6975
- 事务应该在ApplicationService或DomainService中定义,具体位置根据情况决定。
70-
- 事务范围应尽量短,事务中不应包括远程服务调用及消息队列操作。
76+
- 事务范围应尽量短,事务中不应包括远程服务调用及消息收发操作。
77+
- 关于消息的发送应遵守以下约定:
78+
- 消息发送应该封装成独立的类,类名类似于xxxMessageProducer, 类定义放在DomainService目录下。
79+
- xxxMessageProducer类似DomainService,可以由其他的DomainService或ApplicationService调用。
80+
81+
- 关于消息接收应遵守以下约定:
82+
- 消息接收的类应定义在Infrastructure层中,命名类似于xxxMessageConsumer;
83+
- xxxMessageConsumer调用ApplicationService来完成实际处理。
84+
- xxxMessageConsumer类似xxxController,都是由外部调用发起。
82.3 KB
Loading

0 commit comments

Comments
 (0)