问题描述
在改bug过程中,我发现我需要在创建用户的函数下调用另外一处application service下的函数。
相当于我想在一个应用服务中调用另外一个应用服务。
分析:
网上找到的回答:
I don't suggest to call an application service from another service in the same domain. Application services are designed to be called from UI layer. It implements audit logging, authorization, validation... and they will not probably needed if you use a code in the same application layer.
An application service method is a public endpoint of your application. Calling an application service from another is like going out of your application and entering from a different point. You also probably don't want to change an application service method if another application service method's signature changes (because of a requirement change in UI).
My suggestion is to seperate the shared code into another class (probably a domain service) and use from both application services.
简单来说:
不要再一个应用服务内调用另外一个应用服务。应用服务层是程序的公共端点。不要在这层相互间调用,会引起结构混乱。
建议是将多个领域服务共同用到的部分单独抽离到一个类里面。通常来说,在ABP里面,就是下沉到领域服务层domain。
那么打开《领域驱动设计》,看一下一个重要的概念:隔离领域
未来防止领域的职责与系统的其他部分混在一起,我们应该应用Layered Architecture(分层架构)把领域层划分出来。
简单理解:一个入口不应该通向另外一个入口。