SpecPattern icon indicating copy to clipboard operation
SpecPattern copied to clipboard

Usage with DDD

Open dgaspar opened this issue 5 years ago • 2 comments

Let's say I want to rely on a Specification inside my domain model's setter method (that will mutate the object) and reuse it when validating a Command at the Application layer (and be able to map the error back to the right UI field).

If my ISpecification<T> uses the domain model as T, then I first need to create a "corrupted" domain object (one that doesn't respect the invariants) to then be able to validate it against the specs. If my ISpecification<T> uses the application layer's DTO as T, then I can't reuse it in the domain method because they're not the same type..

Would you be able to add a Create(Movie movie) controller action to this repo, to demonstrate how you would deal with the above problem, please? Would you still rely on the Specification pattern for that command validation (i.e., having common/reusable validation units)?

dgaspar avatar Oct 22 '20 10:10 dgaspar

Yeah, that's a good question. I plan to write an article on this topic, will include the Create method there.

vkhorikov avatar Oct 23 '20 10:10 vkhorikov

Here's the article for the record: https://enterprisecraftsmanship.com/posts/specification-pattern-always-valid-domain-model/

vkhorikov avatar Aug 31 '21 13:08 vkhorikov