I am currently facing a few issues when implementing the logic in one of my Aggregates.
Imagine an "Account" aggregate, which has email
, password
, verified
and verificationDate
fields (basically credentials and verification status).
When a new Account is created, it has verified = false
, and verificationDate = null
.
The email should be validated: an account cannot exist with an invalid email (abc@ is invalid). The password should be validated too, and encrypted.
The issue is: if the validation happens when constructing the Aggregate, it would be triggered everytime it is returned by a repository. I've thought of putting that logic in a service, but then it would be possible to create an invalid Account if I bypass the service.
Where should this validation / transformation logic happen ?