服务层的相互依存 [英] Service layer interdependency

查看:111
本文介绍了服务层的相互依存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设计它使用一个服务层一个asp.net MVC应用程序。如果我们有依赖于其他服务的服务?因为,举例来说,假设我们有以下型号:

I am designing an asp.net mvc application which uses a service layer. What if we have a service which depends on another service? For, instance, suppose we have the following model:

class UserService : IUserService
{
    //implementation requires IEmailService
}    

当然,具体实施EmailService可注入UserService的构造,但在我的理解,一个服务层应该UI和域模型之间进行调解,它就像一个门面。我想在这样UserService依靠IUserModule和IEmailModule的方式定义另一层,这样我们可以打破的服务,服务的依赖较低层(在我的情况下模块层)之间的依赖关系。它是一个正确的做法?

Sure, the concrete implementation EmailService can be injected into the constructor of UserService, but in my understanding, a service layer should mediate between UI and Domain Model, it's like a facade. I would define another layer in such a way that UserService depend on IUserModule and IEmailModule, in this way we could break the dependency between services, services being dependent on a lower layer (in my case module layer). Is it a correct approach?

推荐答案

在一个共同的DDD的架构,你会发现2种服务域服务(其坐标实体之间的业务操作)和应用服务(其依赖于域名服务,并包含相关的应用程序,而不是业务逻辑如导出为PDF的任务之一是应用程序的任务。应用折扣是业务逻辑的任务)。

Inside a common DDD architecture you'll find two kind of services Domain services (whose coordinate business operations among entities) and Application services (whose depend on the Domain services, and contain tasks related to the application and not to the business logic e.g. export to pdf is an application task. apply a discount is a business logic task).

所以,如果你只有一种服务,这是我想涵盖的责任。是完全有效的有相关性。

So if you only have a kind of service, which I suppose covers both responsibilities. is totally valid to have interdependencies.

这篇关于服务层的相互依存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆