vkhorikov / SpecPattern

Source code for the Specification Pattern in C# Pluralsight course

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Usage with DDD

dgaspar opened this issue · 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)?

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