Is this DDD Specification a good practice or not?
Hi friends, hope you're all doig well,
I'm working on a project by implementing the
DDD
(Domain Driven Design
),
As you know that one of the core concepts of DDD
is the Specification Pattern
(Specifications),
I have written the following Specification
:
Please could you tell me if this is a good implementation for a specification, or this just wrong manner, because this is the first time I write a specification that needs to deal with database?
Please share with me your experience guys, and massive thanks in advance <3
For more info and definition of the Specification<T>
class take a look here :
https://github.com/MbarkT3STO/ExpenovaApp/blob/main/Source/ExpenseService/ExpenseService.Domain/Specifications/Specification.csGitHub
ExpenovaApp/Source/ExpenseService/ExpenseService.Domain/Specificati...
Contribute to MbarkT3STO/ExpenovaApp development by creating an account on GitHub.
4 Replies
you should only apply the rules on the specification.. do not make the async call in the configure rules. you should only configure the rules and someone else AKA as the repository is executing them.
you can take a look in this repo for examples
https://github.com/dotnet-architecture/eShopOnWeb/tree/main/src/ApplicationCore/Specifications
you can always read some simle examples here:
https://deviq.com/design-patterns/specification-pattern
GitHub
eShopOnWeb/src/ApplicationCore/Specifications at main · dotnet-arch...
Sample ASP.NET Core 8.0 reference application, powered by Microsoft, demonstrating a layered application architecture with monolithic deployment model. Download the eBook PDF from docs folder. - do...
DevIQ
Specification Pattern | DevIQ
One Domain-Driven-Design solution to the problem of where to place querying, sorting, and paging logic is to use a Specification.
Thanks for your time and response,
But as I know that the second link is implementing the specification pattern in generic case, but I'm here dealing with
DDD
and the Specifications
of DDD
should take a Domain Entity
to tell you if satisfied or not ( and maybe I'm wrong )
But anyway thanks a lot for you time and help I appreciateI am aware that you are talking about DDD but i see almost no difference in any specification and ddd.. if we take your implementation i guess the check has access to the DB in order to check the uniqueness i would recommend to extract all the data in the application layer and then just push the aggregate that hold all the data into the specification. That way you are able to run multiple checks together and build some complex business rules in the specification.
Clear man <3,
What about this one ? what do you think ?