首页 > 解决方案 > 您是否应该在不同域的服务层中访问另一个域的存储库层?

问题描述

我有 2 个域,域 A 和域 B。每个域在 spring boot 项目中都有自己的控制器、服务和存储库层。让服务 A 调用存储库 B 的数据会不会出错?这会破坏任何形式的 DDD 或微服务架构吗?

标签: spring-bootdomain-driven-designmicroservices

解决方案


When the Controller is bypassing the Service this organization is often called a relaxed layered architecture, as layers are allowed to skip around their adjacent neighbor(s):

Relaxed layered architecture

According to Clean Architecture, chapter 34:

bypassing the business logic layer is undesirable, especially if that business logic is responsible for ensuring authorized access to individual records, for example

and

Web controllers should never access repositories directly

So in your case Service A should not be able to make a call to Repository B's data directly. All communication should be done via Controller B.


推荐阅读