DDD Using Specification pattern for Validation

Although you may use your Specifications classes for validation, I would suggest you keep them as separate concepts within your domain. You may find that you need to re-use the same underlying specifications but need to return different “Failure Reasons” depending on purpose and context. See this article for more details.

The author of the post referenced above has also kindly shared code to github and posted the code as NCommon. Review these areas in particular:

Specifications: https://github.com/riteshrao/ncommon/tree/v1.2/NCommon/src/Specifications

Validations: https://github.com/riteshrao/ncommon/tree/v1.2/NCommon/src/Rules (especially the classes for ValidationResult and ValidationError)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)