First dont confuse it with service class which is actually a gateway class to interact with database.
Service layer as containing several different type of objects, each with its own kind of role and dependencies.
Types of Service in MVC
- Application Services (Action/Command/UserCase classes)-contain business logic that releted to client interaction ex-buycar,SaleCar,Login,Register.
Note :these services orchestrate the steps required to fulfill the commands imposed by the client. While these services shouldn't have "business logic" in them, they can certainly carry out a number of steps required to fulfill an application need.
Relation to diagram :
->Typically, the Application Service layer will make calls to the Infrastructure Services, Domain Services, and Domain Entities in order to get the job done.
->The Application Service can only be called by the Controller. Since the Application Service orchestrates application workflow, it would make no sense for them to be called by the Domain Service (or even by themselves) - a workflow has only one single starting point; if an Application Service could be called by other entities within the domain model, it would imply that a workflow has an indeterminate number of starting points
- Infrastructure Services (Utility/Helper classes)-contain business logic that is not directly client releted. These are services that typically talk to external resources and are not part of the primary problem domain such as performing some calculation,emailing etc
- Note :These are services that typically talk to external resources and are not part of the primary problem domain. The common examples that I see for this are emailing and logging. When trying to categorize an Infrastructure service, I think you can ask yourself the following questions:
If it will affect your domain model, then it's probably a "Domain Service." If, however, it will simply affect your application, then it is probably an Infrastructure Service. So for example, if I removed Email Notifications from an application, it probably wouldn't affect the core domain model of the application; it would, however, completely break the usability of the application - hence it is an Infrastructure service (and not a Domain Service).
- If I remove this service, will it affect the execution of my domain model?
- If I remove this service, will it affect the execution of my application?
- Relation to diagram-In my diagram, the Infrastructure service can only be invoked by the Application Service
- Domain Services (Dao classes)->These are used to perform CRUD(create,read,update and delete) operation in database.