New Rules and Message Capturing for Validation in Lokad Shared
I just wanted to share that a couple of new rules have been added to the Validation Application Block along with the ability to capture messages.
Referenced article has been updated accordingly.
Capturing rule output
Normally rules operate in two different logical contexts.
- Validation: invalid data is not expected. When such thing happens, we've got to break the execution by throwing the exception.
- Business rules: it is assumed that we can have multiple problems and still be able to continue, while capturing the messages.
Statements like Enforce.Argument or _scope.Validate correspond to the first approach - validation and protection of the code.
Second approach is more common to the business engines and situations, where the errors have to be sent across the logical boundaries (i.e. web validation).
You can achieve such behavior by using statement like:
var messages = Scope.GetMessages(order, "order", DomainRules.ValidOrder);
If none of the rules had anything to say, then the collection, being returned, will be empty.
PS: Thanks to Sean Kearon for reminding me about this one.
Tuesday, November 25, 2008 at 5:03
Reader Comments (1)
Thanks Rinault. I thought it would be in there somewhere :)