Business Rules in project
I know that the business rules belong in the Business Layer but I need help understanding when and why they are happening in the example. The example seems to set business rules on an object in the Business Layer when mapping data being retrieved from the database. I don't see the relevance in that and what the purpose is in setting or validating data retrieved from the database. How does that help?
Dennis Tucker, Aug 03, 2011
Dennis, it seems you are a little confused as to how the Business Rules work in their framework. It is a little complicated, but it's not validating data from the database. It's validating data when it comes into the service layer from the presentation layer.
The way it works is, when a new business object is created, all the rules for that class populate a collection of rules, that then wait to be validated in the service layer.
When the object is passed into an Insert or Update method, for example, the Validate() method is called which iterates over the rules collection and compares the rule with the property value. If the rule passes, then it returns True, otherwise it returns False. Then it passes a message back up to the presentation layer.
If you look at the WCF service implementation class and go into any of the Set[class name] methods, you'll see the [object].Validate() method called in an IF statement. Inside the IF statement there's a FOREACH statement that iterates over the ValidateErrors collection. This is where the validation occurs.
I hope this helps clear this up.
King Wilder, Aug 08, 2011