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?
When calling the attachImage
method to a Car
, i.e. in the domain object.
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?
Agreed. The space constraint is an infrastructure concern, not the domain. Different infrastructure would remove the constraint.