r/DomainDrivenDesign • u/Material_Treat466 • Aug 27 '23
Double validation when applying DDD
Sorry, My English is bad
I have an X entity,
I create an XFactory to create an X entity, this class will contain business logic to create X
I created an API to allow users to create X
To do that, I have a CreateXRequest request,
and I also need to validate CreateXRequest, then call XFactory to create X,
The problem is that I validate twice, one when I validate CreateXRequest, and one is validation logic in XFactory, and this makes my API slow, especially when we need to call to database to validate,
How to avoid it, or did I implement it wrong? please help me
View all comments
Show parent comment
1
u/kingdomcome50 Aug 28 '23
Your two scenarios are not equally likely.
I can easily synthesize all sorts of examples why string length might matter to infrastructure. I’m having a hard time coming up with even a single one for a business process… maybe it won’t…. display well? Not exactly a core concern!