Search code examples
domain-driven-design

DDD: Would it be correct to think this piece of logic fits better in an application service rather than a domain object?


Imagine we have a domain object called Car.

Users can upload multiple images of their car.

However, due to database space considerations (slightly contrived example here), users can only upload a maximum of 3 images.

My question is, where should this check be performed?

  1. When calling the attachImage method to a Car, i.e. in the domain object.

  2. In an application service, i.e. outside the domain.

My opinion is the domain itself doesn't care how many images are attached to a Car. It could be 3 or 10 or 1000, the domain will function correctly regardless.

Caring about database space is not a concern of the domain, and therefore the check should be performed at an application level.

Would this logic be correct?


Solution

  • Agreed. The space constraint is an infrastructure concern, not the domain. Different infrastructure would remove the constraint.