How to add aditional information or properties to Csla 4.0 BrokenRules instances

How to add aditional information or properties to Csla 4.0 BrokenRules instances

Old forum URL: forums.lhotka.net/forums/t/9060.aspx


Andreas posted on Thursday, June 10, 2010

Hi,

in Csla 3.x we were able to add aditional infomation to BrokenRules by using DecoratedRuleArgs in the BusinessRule definition. How can I do this in Csla4.x? 
For example, the Description Property is not sufficient for us. We need additional infos like "ShortDescription", "LongDesciption", "HelpText" "HelpLink" etc. In Csla3.x we than used the RuleDescription class to get back the information, when the rule was broken.

Regards,
Andreas

 

RockfordLhotka replied on Thursday, June 10, 2010

In CSLA 3.x you could provide extra information to the rule, but you couldn't extend the BrokenRule type that is contained in BrokenRulesCollection. To provide extra information to the rule you would create a subclass of RuleArgs or use DecoratedRuleArgs.

In CSLA 4 you provide extra information to the rule by adding properties to the rule class. In CSLA 4 a rule is a type, not a method. And it is your type, so you get to define the properties on that type - which means you can have properties like ShortDescription directly on your rule.

Or am I misunderstanding your question? Or misremembering some detail from 3.x?

Andreas replied on Friday, June 11, 2010

In Csla 4.x and Csla 3.x the "only thing" we get when rules are broken is a collection for BrokenRules instances. So how can I access the coresponding BusinessRule instance to get to my custom properties?
In Csla 3.x the dictionary (Key, Value) of DecoratedRulesArgs were appended as arguments to the RuleName (uri argument syntax) so I was able to get my additional information by parsing the BrokenRule name, using the helper class RuleDescription.

RockfordLhotka replied on Friday, June 11, 2010

The BusinessRule base class has a protected RuleUri property, which you can use to add extra values to the RuleName - very much like in 3.8, but I think more flexible.

Specifically, you can use the AddQueryParameter() method to add property values to the URI.

Copyright (c) Marimer LLC