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 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 of a Domain class via the new operator or through the Domain factory approach discussed earlier in this chapter. Typically, the Domain class custom methods are called in this context.
  • Domain layer: Other Domain classes can call other Domain classes; for example, the Races Domain class can have some functionality it implements that also requires the use of a method on the Contestants Domain class.
Note that it is entirely acceptable to have a Domain class with no Service class code referencing it at all, such as in the case where the Domain class solely implements the code for use in an Apex Trigger context and doesn't contain any custom Domain methods. Then, the only invocation of the Domain class will be indirect via the trigger context.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.125.2