adding instance rules

adding instance rules

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


fsl posted on Monday, January 04, 2010

How do I add an instance rule to a business object?

If I use ValidationRules.AddInstanceRule, the rules is never checked..

RockfordLhotka replied on Monday, January 04, 2010

You have to override AddInstanceBusinessRules() to call AddInstanceRule().

But I strongly recommend against doing this. There is a major performance and memory consumption cost to using instance rules, and I am still very seriously considering eliminating them from CSLA .NET 4.

jkellywilkerson replied on Monday, January 04, 2010

Is there an example of how to handle adding custom ValidationRules other than using AddInstanceRule() in the override in the Expert C# 2008 book?

Kelly.

RockfordLhotka replied on Monday, January 04, 2010

jkellywilkerson:
Is there an example of how to handle adding custom ValidationRules other than using AddInstanceRule() in the override in the Expert C# 2008 book? Kelly.

No, this is the only way to add per-instance rules currently.

In CSLA 4 I intend to do some pretty substantial changes to the business rules subsystem - something for discussion on its own thread later.

fsl replied on Monday, January 04, 2010

Thank you for the quick reply..

I'm now overriding AddInstanceBusinessRules() and rules using methods defined in the enclosing class are executed. But not rules using delegates that are passed to the instance.. I'm wondering why this is the case..

RockfordLhotka replied on Monday, January 04, 2010

fsl:
Thank you for the quick reply.. I'm now overriding AddInstanceBusinessRules() and rules using methods defined in the enclosing class are executed. But not rules using delegates that are passed to the instance.. I'm wondering why this is the case..

Any external rules would need to be public in scope, and would need to remain in scope through the life of the app. In other words, they'd need to be static, or be methods off a singleton or something.

At least that's my recollection. I haven't looked at or used instance rules since 2005, so my memory of the details could be a little fuzzy.

Copyright (c) Marimer LLC