Dependant Business Rules! Is it possible?

Dependant Business Rules! Is it possible?

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


guyroch posted on Wednesday, February 27, 2008

It's been a while since I posted but it's never too late to get back in the game :)

A developer in my team has a use case that requires a business rules to be dependant on another business rule.  We are using CSLA 2.0.

Business Rule A

   Business Rule B (is dependant on A)

   Business Rule C (is dependant on A)

Business Rule D

In this example Business Rule B and C and dependant on A in that A, B, and C has to give the green light for A as a whole to have a green light.  If A is not met, then B and C must NOT be executed.  D on the other hand will always be executed.

Any way we can accomodate this use case with CSLA 2.0

Much appreciated

ajj3085 replied on Wednesday, February 27, 2008

Good to see you're back.

I've done this by simply having rule A call rule B and C... something like:

private static bool RuleA( MyClass inst, RuleArgs e ) {

bool result;

result = RuleB( inst, e );
if ( result )
   result = RuleC( inst, e );
   if ( result )
    // rule A check here

return result;
}

Of course that stops C and A from running if B returns false, but I don't see a way around that.

guyroch replied on Wednesday, February 27, 2008

Umm... already thought about that, I was hoping for a solution that did not tightly coupled the dependant business rules by encapsulating them in if statements.

I probably chasing a ghost here :)

JonM replied on Wednesday, February 27, 2008

CSLA 3.0 can do shortcircuiting.  Basically you can keep other rules from running for the same property.  This isn't exactly what you want but it will probably get you close.  I'm not sure how you control the rule order (perhaps it is just the order you add then to the validationrules collection).

Inside of the rule:

  e.StopProcessing = true;

Copyright (c) Marimer LLC