Chained Rules & RuleContextModes

Chained Rules & RuleContextModes

Old forum URL:

Peran posted on Thursday, December 22, 2011

Hi Jonny,

I have been playing with your recent business rule changes (CanRunAsAffectedProperty etc) and noticed different behavior if a rule is run as an inner rule.

The standard way of running inner rules, within a gateway rule, bypasses any checks on the RuleContext.ExecuteContext


    if (MyCondition)

        var chainedContext = context.GetChainedContext(thisMyInnerRule);


If my inner rule has CanRunAsAffectedProperty = false, I would expect it *not* to run if it is an affected property regardless of it being part of a chain or not.  Currently the rule runs if it is an inner rule.

I propose this addition to RuleContext:


        public void ExecuteChainedRule(Csla.Rules.IBusinessRule chainedRule)

            var chainedContext = GetChainedContext(chainedRule);
            if (Csla.Rules.BusinessRules.CanRunRule(chainedRule, chainedContext.ExecuteContext))

Which would also require Csla.Rules.BusinessRules.CanRunRule to be changed from private to internal.

And my gateway rule could be written as:


    if (MyCondition)



I think this also simplifies the syntax for running chained rules.

Let me know what you think.




JonnyBee replied on Friday, December 23, 2011

Hi Peran,

Great idea and added to Bugtracker:

I wonder if we should just call the method RuleContext.ExecuteRule

The Using CSLA 4 ebook also call these outer and inner rules but to a programmer it would simply be on or more (inner) rules to be executed from the this  rule's context.

What do you think?


Peran replied on Thursday, December 29, 2011

'ExecuteRule' method name works for me.  I added the word 'Chained' as it was replacing the call to 'Get*Chained*Context'.






I renamed the parameter innerRule to go with the documentation.

JonnyBee replied on Thursday, December 29, 2011

Great!  already checked in to trunk.

Copyright (c) Marimer LLC