Calling the Domain layer
The Domain layer is positioned with respect to visibility and dependency below the Service layer. This, in practice, means that Domain classes should not be called directly from the execution context code, such as Visualforce controllers, Lightning Web Component controllers, or Batch Apex, as it is the Service layer’s responsibility to be the sole entry point for business process application logic.
That being said, we saw that the Domain layer also encapsulates an object’s behavior as records are manipulated by binding Apex Trigger events to methods on the Domain class. As such, Apex Triggers technically form another point of invocation.
Finally, there is a third caller type for the Domain layer, and this is another Domain class. Restrict your Domain class callers to the following contexts only:
- Apex Triggers: This calls via the
fflib_SObjectDomain.handleTrigger
method. - Service layer: This layer directly creates an instance...