BrokenRules Event?

BrokenRules Event?

Old forum URL:

idroesse posted on Tuesday, May 04, 2010

Hi guys, I'm looking for something that can help me to notify operator that one (or more) rules had been broke.  Is there an event to use?

I'm developping a WPF application and I want to create a Behaviour to attach to every Window in wich display brokenrules descriptions.

Please accept my apologies for any spelling mistakes


RockfordLhotka replied on Tuesday, May 04, 2010

CSLA follows the approach defined by data binding, which means that the PropertyChanged event is used to detect that a property has changed, and therefore that a check for broken rules should be made.

Specifically, when a PropertyChanged event is handled, you can use the IDataErrorInfo interface to get one broken rule related to that particular property.

IDataErrorInfo turns out to be pretty limiting (only returning one error, and no severity information), so you can also use the BrokenRulesCollection property of a BusinessBase object to get the complete list of broken rules, and then you can use LINQ queries to filter/sort the list as you wish. This gives you access to broken rules of all three severity values, and of all properties.

But even in this case, the trigger is the PropertyChanged event.

idroesse replied on Tuesday, May 04, 2010

Perfect, so I can trigger IsValid property on my Root Object.  But BrokenRulesCollection on Root object contains only rules defined for it, not for its children.  What I need to use to get complete BrokenRulesCollection (root + children)?

Thanks again,  Enrico

RockfordLhotka replied on Tuesday, May 04, 2010

You need to write code in your business class to do this rollup. The BrokenRulesCollection class has a Merge() method that allows you to merge multiple broken rule lists into a single list, making it relatively easy to create a GetAllBrokenRules property on your business object.

As always, I recommend that you have your own custom base class between BusinessBase<T> and your actual business class, so (assuming you are using managed backing fields) you can write a general version of this property in your custom base class.

The one thing to be aware, is that the broken rules items in the broken rules list don't contain the name of the business object - so the merged list may not be exactly what you want, and you might want to create your own merged list type that has more information.

You can also look at the CSLAcontrib project on codeplex, where there's a Windows Forms tree control that shows all broken rules for an object graph. You can probably borrow some ideas from that control and adapt it to WPF.

JoeFallon1 replied on Sunday, May 16, 2010

I have posted code for how to retrieve all broken rules before.
See this thread:



Copyright (c) Marimer LLC