Question

Regarding domain driven design:

I have domain models, repositories and services. My questions is regarding the modelling of the domains.

For instance, I have a database table with Employee, CountryId, State Id

  1. How would I model my domain object, would I model it with the id or with the literal value?
  2. At what point would I resolve the Id value to the literal value?
  3. Should I use the services to point to the CRUD operations of the repository or is that an anti-pattern?

Your help would be highly appreciated.

Was it helpful?

Solution

How would I model my domain object, would I model it with the id or with the literal value?

Is the id part of the domain or is only used by your relational database? In the latter case you would not model using the id. Strictly speaking you are thus also not allowed to store the id in your entities, but this would require you to create data transfer objects, which would probably mirror your entities in almost every way. Therefore personally I do not take DDD so strictly.

At what point would I resolve the Id value to the literal value?

Your infrastructure layer should take care of this.

Should I use the services to point to the CRUD operations of the repository or is that an anti-pattern?

Services may call the repositories. It would however be an anti-pattern if there are two ways to (seemingly) achieve the same effect within a codebase. You could expose your services to a higher layer (and hide the repositories from that layer) and use the repositories within those services. In between it would be possible to have some additional logic.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top