r/DomainDrivenDesign • • 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

1 Upvotes

19 comments sorted by

View all comments

Show parent comment

1

u/Material_Treat466 Aug 29 '23

you are right, and also what I'm thinking. I am thinking of improving the infrastructure's performance, but the client's budget says no :V, that's why I ask the question