Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

分层问题讨论 #30

Open
chunpat opened this issue Sep 22, 2020 · 1 comment
Open

分层问题讨论 #30

chunpat opened this issue Sep 22, 2020 · 1 comment
Labels

Comments

@chunpat
Copy link

chunpat commented Sep 22, 2020

Service 岗位职责

  1. 实现项目中的具体功能业务。所以 Service 中定义的方法名,应该是用来描述功能或业务的(动词+业务描述)。比如handleListPageDisplayhandleProfilePageDisplay,分别对应用户列表展示和用户详情页展示的需求。
  2. 处理 Controller 中传入的参数,进行业务判断
    3.(可选)根据业务需求配置相应的 Criteria 和 Presenter 后(不需要的可以不用配置,或者将通用的配置到 Repository 中)
  3. 调用 Repository 处理数据的逻辑
  4. Service 可以不注入 Repository,或者只注入与处理当前业务存在数据关联的 Repository。比如,EmailService中或许就只有调用第三方 API 的逻辑,不需要更新维护系统中的数据,就不需要注入 Repository;OrderService中实现了订单出库逻辑后,还需要生成相应的财务结算单据,就需要注入 OrderReposoitoryFinancialDocumentRepository,财务单据中的原单号关联着订单号,存在着数据关联。
  5. Service 中不允许调用其他 Service,保持职责单一,如有需要,应该考虑 Controller 中调用

对于上面提到的service的职责,如果涉及到EmailService中或许就只有调用第三方 API 的逻辑是不是另外弄个logic逻辑层好点呢?这样service只负责简单的业务逻辑,像商城下订单复杂的业务逻辑验证也可以放到logic层。

@jiannei
Copy link
Owner

jiannei commented Sep 23, 2020

@chunpat 复杂的业务会考虑拆分子 service,配合 job和event ,就不考虑增加分层了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants