Interdependent properties csla 4.0

Interdependent properties csla 4.0

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


Natasha posted on Wednesday, May 26, 2010

Hello, Rocky!

Could  you answer my question about Interdependent properties. We have trouble with "AddDependent Property". Is it exist in CSLA.NET 4.0 version? Was it changed or removed?

Natasha.

RockfordLhotka replied on Wednesday, May 26, 2010

It is removed. Rules now have the concept of an "affected property" that provides similar functionality. A rule is attached to one primary property, but when that rule is complete, all rules for any affected properties are then executed.

pneurohr replied on Thursday, June 03, 2010

How do you add Properties to the AffectedProperties collection on the rule?  I only see a getter and no accessor.

 

Thanks,

Peter

RockfordLhotka replied on Thursday, June 03, 2010

You use the Add() method on the collection:

AffectedProperties.Add(YourProperty);

See the last class in this file:

http://www.lhotka.net/cslacvs/viewvc.cgi/core/trunk/Source/Csla.test/ValidationRules/ValidationTests.cs?view=markup

pneurohr replied on Friday, June 04, 2010

I was trying to do it as part of the call to add rule.  The property needs to be placed in to the constructor. 

I have another question though.  When I try to use context.AddOutValue to modify another property on the business object, an exception is thrown since the property is not in the affected properties collection.  I thought that collection was used to fire related rules not list the properties that can be changed.

RockfordLhotka replied on Friday, June 04, 2010

It is used for both.

If your rule changes a value, it is important to trigger the rules for that output property, otherwise you end up with a rule on PropertyA putting what is effectively an invalid value into PropertyB, and nobody would know.

Forcing out values to be in the affected property list ensures you can't get into that hard-to-debug situation.

pneurohr replied on Monday, June 07, 2010

Hopefully I have one final question.  I am trying to write a rule that runs async but it uses a property in a child business object for both input and output.  I can't seem to get it work correctly. I tried making the backing field internal and passing that into the rule constructor but it resulted in a strange type mismatch when the SetOutValue was called.  Is there anything else I should try?

 

Thanks

RockfordLhotka replied on Monday, June 07, 2010

Unfortunately that's not a supported scenario. That would require inventing some string-based binding syntax to describe a path through the object graph, and incurs a bunch of risk around the child object moving while the rule was running (if you added/removed other items in a list, etc) - so it would also require some external object identity marker for all objects (like a Guid). In short, it gets very complex very fast.

The answer is to either put the property on your parent object, or put the rule in the child object and have the parent invoke a method on the child that runs the rule.

Copyright (c) Marimer LLC