Edit
To clarify my original problem, I rewrote the question with a more “DDD” contini, common patterns and discussion arguments. The original version can be found in revisions .
Where and how are identities formed for entities / aggregate roots within a domain when DDD is used correctly?
I need to assign unique identifiers to my objects, whether when creating or saving. These identifiers can be in several styles.
- Calculated (based on the characteristics of the object, therefore, based on the requirements of the business)
- Natural (based on a specific set of rules, therefore, based on business logic)
- Surrogates (based on randomly generated values without a business value)
There are many approaches to the task of generating and assigning identifiers: from using factories to create identifiers, delegating to the infrastructure using ORM or generating a database , etc. However, if you correctly use DDD, where and how should identifiers be generated, given that we do not want unfashionable domain models to implement services in essence ?
Requirements above
- No anemic domain models
- Essentially no dependency on injection services
Possible approaches
- Plants
- Double submission (can it be used to generate identity?)
- Generation inside repositories
- Generation within the infrastructure (e.g. ORM or database)
- Injection services in essence
source share