DEV Community

Discussion on: Data Validation: Scratching Surface of Code Responsibility

Collapse
 
rytheturtle profile image
RyTheTurtle

That's a great point, and I agree the domain logic should not leak in to the system boundary / infra layer.

In my experience, the answer is that any particular field or validation doesn't have to exclusively be validated in one part or another. To take the same example, my answer would be two fold:

  • infra layer: Validate the age is present and is a positive integer.
  • domain layer: Validate the domain-specific rules for allowed ages for users.
Thread Thread
 
oberonus profile image
Alexander Demin

Yes, 100% agree. The main point is that this is a question of code responsibility. It is not about specific fields, but more about the validation scope that can be done in specific place while still having strong boundaries between layers.

Some pieces of validation can be even duplicated, e.g. domain logic can be called not from infra, but from another domain service, and proper validation still should be applied. So here is the question - what can/should be placed in infra layer and for what reason -IMO it is almost always a question of optimization.