1

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
  • 15
  • 3
  • Where are the transaction boundaries? – Nathan Hughes Mar 19 '22 at 00:16
  • At the moment they are in the Persistence Service, but I have yet to introduce any advanced functionality that may require them in the "Domain" Service Layer. – gandhix Mar 19 '22 at 00:18
  • So for the first of the alternatives you create the object in kne transaction, then pass it into another transaction? – Nathan Hughes Mar 19 '22 at 00:37
  • tbh, I am still learning about Transactions really. I have merely annotated some retrieval methods with @transactional. But your responses have given me some insight into considerations I must make. Do you think splitting the persistence service and the domain service in this way is a bad idea? – gandhix Mar 19 '22 at 00:46

1 Answers1

1

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
  • 5,269
  • 2
  • 14
  • 22