可以从一个应用程序服务调用另一个应用程序服务吗?

Paw*_*iak 5 service domain-driven-design

这是一个 ASP.NET MVC 网站。

遵循领域驱动设计,我们有一个服务层。我们的控制器要求应用程序服务类执行各种任务,然后将结果路由到视图。

业务逻辑由服务类执行。

例如,我可能有一个AccountTasks类负责注册用户、编辑他们的首选项等。现在我还需要能够在用户注册或更新其用户首选项时自动订阅新闻通讯(然后我会更改时事通讯订阅)。

因此,时事通讯订阅功能与帐户注册/修改密切相关。

但是,我觉得最好有一个单独的NewsletterTasks服务类来处理订阅/更新/取消订阅操作。

但这个类不会被控制器使用,而是被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
Run Code Online (Sandbox Code Playgroud)

或者,我会让控制器调用第AccountTasks一个,然后使用结果调用NewsletterTasks. 但通过这种方法,我觉得控制器对工作流程了解太多,而它应该简单地传递数据和结果。

任务是应用程序服务类,该项目基于 S#arp 架构,并进行了来自Who Can Help Me 的一些修改- 其中包括某些事物的命名约定。

可以NewsletterTasks从打电话AccountTasks吗?你会怎么做?

Vij*_*tel 5

我很想创建一个显式的UserRegistration 域服务

-> 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
Run Code Online (Sandbox Code Playgroud)

这反过来回答了您的问题:是的,可以从您的服务调用其他服务

希望有帮助!