CSLA 3.5 Code-reduction and Interdependent Properties

CSLA 3.5 Code-reduction and Interdependent Properties

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


Frazer posted on Monday, April 28, 2008

In Chapter 8 of Expert vb2005 Business Objects, Rocky introduces the notion of interdependent properties with the Started and Ended SmartDate properties.

In the book's version of the code, he calls ValidationRules.CheckRules on the interdependent property BEFORE calling PropertyHasChanged on the current property (thereby validating the interdependent property first, and then the current property).

Having read Rocky's Fe blog post of code reduction in 3.5 - I am unsure how interdependency is implemented when using this coding construct.

Given this as a starting point:

Private Shared StartedProperty As PropertyInfo(Of SmartDate) = RegisterProperty(Of SmartDate)(GetType(Project), New PropertyInfo(Of SmartDate)("Started", New SmartDate(True)))
Private pvStarted As SmartDate = StartedProperty.DefaultValue
Public Property Started() As SmartDate
Get
Return GetProperty(Of SmartDate)(StartedProperty, pvStarted)
End Get
Set(ByVal value As SmartDate)
SetProperty(Of SmartDate)(StartedProperty, pvStarted, value)
End Set
End Property

The question is: where to insert the ValidationRules.CheckRules("Ended") call to ensure the Ended property is validated before the Started property?

RockfordLhotka replied on Tuesday, April 29, 2008

That technique was obsoleted in version 2.1.

You should add a dependent property in AddBusinessRules() to handle this case - check the CSLA .NET Version 2.1 Handbook for details - though be aware that version 3.5 renamed the method to correct confusing spelling.

Also you can look at the current ProjectTracker code (the Project class) to see how this works.

Copyright (c) Marimer LLC