Skip to content

Creating and validating nested entities #151

Answered by Sairyss
hymair asked this question in Q&A
Discussion options

You must be logged in to vote

You can validate in any place in the entity where it's needed. Any method can validate.
Though, for typical sanity validation (like string/number validation with Zod), I would do it only on the edge of the application where it receives external data (like input DTOs in the controller, or if you query data from external APIs). Invalid data shouldn't go any further from outer layers and shouldn't get to the domain.
In the domain we usually consider that data is already validated by the upper layers, and only validate in some rare cases where we need extra safety, or we only validate business rules (invariants), not the input sanity.
Though, if you absolutely want this extra safety, it's fin…

Replies: 4 comments 5 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by hymair
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
4 replies
@hymair
Comment options

@Sairyss
Comment options

@hymair
Comment options

@Sairyss
Comment options

Comment options

You must be logged in to vote
1 reply
@Sairyss
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants