Member parameters & Dependency parameters
As explained earlier, each parameter in the factory constructor corresponds to a property generated within the modddel.
There are two types of parameters : "member parameters" and "dependency parameters".
Member parameters
"Member parameters" represent properties held by the modddel. For example, in a Birthday
ValueObject :
In this example, date
is a member parameter of the Birthday
ValueObject, as it holds the actual value (the date of the birthday).
Dependency Parameters
On the other hand, "dependency parameters" are used for dependency injection within your modddel. For example, the Birthday
ValueObject might rely on a currentTimeService
for validation. To achieve this, you can annotate the currentTimeService
parameter with @dependencyParam
:
The dependency parameters are not taken into account for data equality, and are not included in the toString
output.
Here is a full example on how to use the dependency parameter :
As you can see :
(A) We annotate the
currentTimeService
parameter with@dependencyParam
.(B) After running the generator, we can access the
currentTimeService
from within the validation method(s) this way :We can also access it from an instance of the modddel :
Like any other instance member, you should NEVER access the instance's dependency parameter(s) from within the "validate" method(s).