开发者

Service layer interdependency

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
}    

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, s开发者_开发百科ervices being dependent on a lower layer (in my case module layer). Is it a correct approach?


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.

Service layer interdependency


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

Well, it's a contract between to sides, not necessarily UI and Domain Model, but commonly.

it's like a facade.

Yes, a good service features a nice facade also accounting for performance.

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?

What does module mean to you? Is IEmailService a service or a module to you? It seems correct to create the Facade in your case for your service. But you provide to few information about your system and your intent and your architectural challenges/priorities.


Dependency injection is something you should avoid as it increases coupling and complexity for an illusion of flexibility. MVC is also something to reconsider before you start your development because it is not good for anything more than simple applications that do CRUD operations. Web Forms is a more proven platform and is better for more usable applications.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜