CSLA 4 - Business Rules: Affecting Child properties

CSLA 4 - Business Rules: Affecting Child properties

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

Jaans posted on Sunday, January 09, 2011

Hi All

We're still converting over to CSLA 4 and have a couple of questions regarding implementing the new Business Rules.

Scenario 1 - Change to property, should have rule affect properties on children.

The BO structure is an editable root with an editable child list - or in our inhouse shorthand expressed as ER -> ECL(EC) : Staff -> TaskList<Task>

So I have a rule class in the root Staff class and I have set the input property to the "triggering" property. When the rule executes it will be affecting the Task objects in the Tasks collection (pointed to by the TasksProperty on the Staff BO).

Where I'm unsure is:

Scenario 2 - Change to property, should have rule affect other properties without triggering property change notification

Before CSLA 4, I could simply just call LoadProperty( ... ) for the property I wanted to change without causing it to fire it's PropertyChanged notification.

How do I achieve the same in CSLA 4? It would appear that specifying the property in context.AddOutValue results in property being "SET" thus triggering the PropertyChanged notification.

Please indicate if anything above is unclear and needs more elaboration.


JonnyBee replied on Sunday, January 09, 2011

Hi Jaans,

Look at the Net\BusinessRulesDemo sample in the samples download.

In short:
AffectedProperties = properties that you will change a value in the rule or properties that should have their rules rerun (like Dependency) after this rule has run (and this property has changed).

I'm not convinced about 2: You do need to raise OnPropertyChanged when a property is changed - especially in WPF/SL/WP and using AddOutValues will help you make this code more generic.


Jaans replied on Sunday, January 09, 2011

Hi Jonny - thanks for you reply.

The sample you suggest unfortunately doesn't have an root object with a child collection where a rule in the root affects items in the child collection.

Scenario 1 - Are you saying I don't need to call "context.AddOutValue( TasksProperty, tasks );" when I'm chaging the items contained in the tasks collection?

Scenario 2 - The issue here is that I need to change a property in the rule execute event, without that change triggering the rules associated with that property. That's what LoadProperty allowed me to do. Any suggestions?


JonnyBee replied on Monday, January 10, 2011


1. If you are changing the child items you shouldn't use context.AddOutValue (as that would replace the entire child list). If you are going to change some of the items then you must use the context.Target.

2. BusinessRules has a LoadProperty and ReadProperty  (similar to ObjectFactory) that allows you to call like this:
    LoadProperty(context.Target, propertyInfo, newValue).
    This will set the property of the given object to the newValue without raising OnPropertyChanged or rerun rules

Jaans replied on Monday, January 10, 2011

Aaa.. brilliant!

2. I didn't notice the LoadProperty on the BusinessRule base class - just what I need.

1. OK... I'll use context.Target then.

Thanks again Jonny!

Copyright (c) Marimer LLC