0

Currently I have a domainObjectPersistenceService which calls DAO functions on the Domain Object, and I have a separate domainObjectDomainService which processes Business Logic. For example, userPersistenceService and userDomainService.

I am unsure whether to handle the initial call to the domainObjectPersistenceService from the Controller directly, or call it from inside the domainObjectDomainService.

What is the preferred way?

@Controller
public class Controller {
   public controllerMethod(int fileId) {
      domainObject = domainObjectPersistenceService.getFile(fileId);

      data = domainObjectDomainService.processFile(domainObject);

      // convert data into DTO

      return dataDTO;
   }  
}

or

    @Controller
    public class Controller {
       public controllerMethod(int fileId) {
          // domainObjectDomainService handles persistence layer calls.
          data = domainObjectDomainService.processFile(fileId);

          // convert data into DTO

          return dataDTO;
       }  
    }

Many thanks!

gandhix
  • 3
  • 1

1 Answers1

0

See Domain Driven Design: Domain Service, Application Service

In your case Controller is Application Service. It is an orchestrator, that retrieves objects from the repository and pass to the Domain Service.
First way is correct.

Eugene
  • 2,332
  • 2
  • 9
  • 14