Why require setting InputProperties?

Why require setting InputProperties?

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

ajj3085 posted on Sunday, December 30, 2012

I'm writing rules which are ignorant of the type to which they are applied, and so I'm using the InputPropertyValues to examine the property values I care about and act on them.

I'm curious though as this has bitten me several times now, why do I need to set InputProperties to an array of PropertyInfo instances to actually get the InputPropertyValues array populated?

Shouldn't this be the behavior all the time?  I am inheriting BusinessRule and passing the property I care about into the ctor that takes a primary property.


JonnyBee replied on Monday, December 31, 2012

InputProperties was considered optional when the new rule engine was written for CSLA 4.x.

This evolves into InputProperties becoming implicit dependencies in CSLA 4.2 and for CSLA 4.5 the InputProperties collection is automatically initialized. 

You could mitigate this for your own code by creating an intermediate base class for your rules. 

I find InputProperties to be very helpful in creating general rules - without and knowledge of the actual object type - and the InputProperties collection should be initialized right away - as AffecteProperties is. This is done for CSLA 4.5 - but will need your own intermediate class of for CSLA 4.3 and older. 

If possible - I would rather inherit from PropertyRule or even CommonBusinessRule. The latter class also inherits from PropertyRule and will provide property for Severity. If you follow the same coding style as in CommonRules your rules may also be configured with the actual Severity to use when they fail.

ajj3085 replied on Sunday, January 13, 2013

Thanks for the response.  It sounds like they are no longer considered optional then in later versions of Csla, and is automatically populated with all of the BOs property values?  I'm on 4.3 at the moment I believe, as I only see BusinessRule to subclass from.

I've found InputProperties helpful as well, I am pretty much using them exclusively, even if the rule can only work with a  single BO.

JonnyBee replied on Sunday, January 13, 2013

No, InputProperties will not be automatically set to all properties and context InputPropertyValues will not automatically be populated with the BOs properties. 

You still need to declare which input properties your rule require. 

This is used to create implicit dependencies, ie when one of the InputProperties is changed this property's rules is also rechecked.

Copyright (c) Marimer LLC