这是一个 ASP.NET MVC 网站。
在领域驱动设计之后,我们有一个服务层。我们的 Controller 要求应用程序服务类执行各种任务,然后将结果路由到 View 。
业务逻辑由服务类执行。
例如,我可能有一个 AccountTasks
类负责注册用户、编辑他们的偏好等。现在我还需要能够自动为用户订阅时事通讯一旦他们注册或更新他们的用户偏好(然后我会更改时事通讯订阅)。
因此,时事通讯订阅功能与帐户注册/修改密切相关。
但是,我觉得最好有一个单独的 NewsletterTasks
服务类来处理订阅/更新/取消订阅操作。
但是这个类不会被 Controller 使用,而是 AccountTasks
类。
所以,工作流程是这样的:
-> request made to controller action
-> controller calls AccountTasks
-> AccountTasks creates a user acoount
-> AccountTasks calls NewsletterTasks
-> NewsletterTasks subscribes the user to the newsletter
-> AccountTasks returns the result to the controller
-> controller fetches the appropriate view and sends it to the client
或者,我会让 Controller 先调用 AccountTasks
,然后使用结果调用 NewsletterTasks
。但使用这种方法,我觉得 Controller 对工作流了解得太多了,而它应该简单地传递数据和结果。
任务是应用程序服务类,该项目基于 S#arp 架构,并进行了一些修改来自 Who Can Help Me - 包括某些事物的命名约定。
可以从 AccountTasks
调用 NewsletterTasks
吗?你会怎么做?
最佳答案
我很想创建一个显式的 UserRegistration Domain Service:
-> request made to controller action
-> controller calls UserRegistrationService
-> UserRegistrationService calls AccountTasks
-> AccountTasks creates a user acoount
-> UserRegistrationService calls NewsletterTasks
-> NewsletterTasks subscribes the user to the newsletter
-> UserRegistrationService returns the result to the controller
-> controller fetches the appropriate view and sends it to the client
这反过来回答了您的问题:是的,可以从您的服务调用其他服务
希望对您有所帮助!
关于domain-driven-design - 从另一个应用程序服务中调用一个应用程序服务是否可以?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4124866/