Validating business rules


Business rules would be "this email is already taken in the database" Here's how I am currently doing it in my register model: One alternative is to create a custom validator attribute.

If you do it in a decision table form, the benefit is that you can check for correctness and completeness of the business rules within the table, which would be a way of validating business rules.My preference is to spread the business logic across custom attributes you can plug and play. Using annotations to validate your models is fine for small applications that require validation, but when your validation rules start to become more and more complicated and your models begin to get more complex then I'd suggest looking at a library like Fluent Validation.The problem with validate your models via attributes is it can be quite messy and you'll begin to suffer from a lot of repetition; where as the benefits you gain from using a library like Fluent Validation are: Thanks for the answer, ill check out fluent validation.Custom validation rules are an advanced topic and covered in Section 38.9, "Implementing Custom Validation Rules." You can also base validation on a Groovy expression, as described in Section 7.5, "Using Groovy Expressions For Validation and Business Rules." When you add a validation rule, you supply an appropriate error message and can later translate it easily into other languages if needed.You can also define how validation is triggered and set the severity level.Section 8.2, "Using Method Validators" explains how to use the Method validator to invoke custom validation code and Section 38.9, "Implementing Custom Validation Rules" details how to extend the basic set of declarative rules with custom rules of your own.

You must have an account to comment. Please register or login here!