Help... CSLA's Rule validation is not for Business Processing.

Help... CSLA's Rule validation is not for Business Processing.

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


gwilliams@msn.com posted on Monday, December 21, 2009

(ducking under the table) Now that i have everyones attention I Need some help in responding to the following statements regarding CSLA.
We have a new project that has been in development for the last few months and I am having trouble communicating some key points with the framework to our offshore team

Little background:
We do not really have any validation rules that would keep a record from being written into the db. There are a few required fields but that is it.
Per a specific contract that a call agent is working; business rules/contract attributes need to be checked. Ie. are certain limits being met.
Again based on specific contracts an external rules engine needs to be called to see if any additional questions need to be prompted to the agent .

The current design that is being proposed is to pass in the specific business object that needs to be validated to a “Helper class”. This then would execute the business rules (contained in the csla object) and return any questions , if applicable, per the rule being run.

Below are comments from team members. I would appreciate any opinions on this matter as I have run out of ideas as to how to best to communicate the implement the business rules, either internal or external.-

Issue #2: Implementing Business Rule Calls through CLSA Validation feature.
Though CLSA provides a very good validation framework to validate simple property information like field length, format and other meta information of the property by setting the property value appropriately at run time. However, we have the constraints like

a. As this returns true/ false, business rules that require questions and answers cannot be implemented using this -- as the response would not be as simple like a boolean (like Q&A).

b. During the call intake process, the call could be put on hold any time. This would require maintaining a lower severity for any business rules implemented via CSLA validation feature - which we don't recommend as it would bring in inconsistency. It would become hard to differentiate between an actual error and warnings.

c. These rules have to be triggered by setting the property values or by calling a method to forcefully execute these rules. Setting properties again and again just to fire the call to BRE through CSLA's validation feature is not efficient and not the right approach. Exposing the method to forcefully execute CSLAs validation rule is as good as calling the instance methods which directly call the services - the only difference being Broken Rule Collection is populated if we use CSLA's validation rule.

d. Maintaining the Broken Rule Collection will be a cumbersome process as it would be required to be reset whenever a invalid rule is overridden.

e. With the instance methods, the rules are called on a need basis. But, with CSLA's Validations Rules, all the rules are stacked-up even if they are not invoked.

f. While Saving, even if a rule was already processed, CSLA would trigger redundant calls to External Business rules engine.

g. We would also like to add that CSLA's Rule validation is not for Business Processing

With this understanding of CSLA's Rule validation, it is not recommended to use it to implement/ run a Business Process.


gwilliams@msn.com replied on Monday, December 21, 2009

Also, i just noticed that i put in the wrong email address when creating my account... email address should be gregwilliams_@msn.com... how do i change this? i have had to create a few accounts due to not getting a response back regarding bad passwords???

RockfordLhotka replied on Wednesday, December 23, 2009

gwilliams@msn.com:
Also, i just noticed that i put in the wrong email address when creating my account... email address should be gregwilliams_@msn.com... how do i change this? i have had to create a few accounts due to not getting a response back regarding bad passwords???

Email me directly and I can try to sort this out.

tmg4340 replied on Tuesday, December 22, 2009

Well... the first thing I'll say is that I certainly wouldn't say that "CSLA's Rule validation is not recommeded to run/implement a Business Process".  And I'd bet that most other forum users would agree with that - after all, they're implementing/running business processes just fine.

Having said that, it may not be ideal for your business process.

The introduction of an external Business Rules Engine and "helper classes" are going to cause you issues, largely for the reasons listed.  Externalizing the business rules either takes control away from your CSLA classes, or makes it rather cumbersome to integrate.  Discussions surrounding a BRE have been had on the forum before, and I don't think we came to a very satisfactory conclusion - but one was made.  So you might do a forum search to see if you can come up with anything.

Having said that, many of these questions are certainly answerable in CSLA.  The "on hold" concept is doable, since I would presume that the status of your business objects changes when the call goes on hold.  Your business rules can leverage that property when evaluating the object.  I don't see that as an "inconsistency", since your business rules should be able to return the severity (warning/error) of the rule based on its current status.

I'm a little confused about the "we need more than a true/false" statement - a rule is either broken or it's not.  So I'm wondering what kind of business rules "require questions and answers" that aren't of the true/false nature?

Along similar lines, the concept of "maintaining the broken rule collection when an invalid rule is overridden" is a problem whether you use CSLA's rules or not.  If your system allows you to say "you know, this broken rule isn't really broken", then I say it's not really a broken (i.e. hard-and-fast) rule to begin with.  CSLA's system allows for warning messages, which don't stop processing, and are probably a better fit for this kind of situation.

In terms of launching the validation rules, they are correct - repeatedly setting property values is inefficient, and exposing the validation methods as publicly-callable is technically no better than creating methods to call the BRE directly.  And that's part of the point - if your business rules are external to your business object, the "real-time validation" concept of CSLA pretty much doesn't apply anymore.  It's much more of a web-style scenario, where you're filling out forms, pressing the "Submit" button, and seeing what breaks.  That's certainly a model that's supported in CSLA, but you're not going to see anything that's significantly better than directly calling your BRE when you need to.

And as for the redundant calls to the BRE when saving, you can always override the Save() method and do your own thing.  I wouldn't necessarily recommend it - what you might call "redundant" I call "a fail-safe against programmers forgetting to call the BRE".  Smile [:)]

I would also argue that CSLA's validation-rule system is much more than just "validat[ing] simple property information like field length, format and other meta information of the property".  It may be tied to properties, but the validation rules are ultimately just method calls - you can do pretty much anything you want.  You are also not restricted to what's supplied in CSLA - you can write your own.  So if your team is suggesting the validation subsystem is simplistic, then I think they need to take a step back and re-evaluate the framework.

Lastly, it's been recognized several times recently that "validation rules" was probably a poor naming choice, and I believe Rocky is planning on doing some rather major overhaul-type work in CSLA 4.0 on the whole business-rules section - including renaming it to "business rules".  There's nothing wrong with writing "validation rules" that do nothing more than data transformation, or other non-rule-type processing.  It's actually become rather common - thus the discussion of the unfortunate name.

HTH

- Scott

ajj3085 replied on Tuesday, December 22, 2009

tmg4340:
Having said that, many of these questions are certainly answerable in CSLA.  The "on hold" concept is doable, since I would presume that the status of your business objects changes when the call goes on hold.  Your business rules can leverage that property when evaluating the object.  I don't see that as an "inconsistency", since your business rules should be able to return the severity (warning/error) of the rule based on its current status.

Also, it may be there's a CallInProgress BO, which validation rules are always warnings and thus savable, and a seperate CallComplete BO, which changes a call from in progress to complete.  This BO would have validation errors preventing it from saving (which would move the call from InProgress to Complete).

tmg4340:
I'm a little confused about the "we need more than a true/false" statement - a rule is either broken or it's not.  So I'm wondering what kind of business rules "require questions and answers" that aren't of the true/false nature?

This sounds very much like a bad design being the culprit.  Instead of a question and answer, and the behaviors which go along with it being a Csla businessbase subtype, they're trying to stuff that into a single method.  Their "rules" are corrisponding to methods when they should be a full blown BO, and a BO to them is nothing more than a collection of rule methods (which they want to alter dynamically).

tmg4340:
I would also argue that CSLA's validation-rule system is much more than just "validat[ing] simple property information like field length, format and other meta information of the property".  It may be tied to properties, but the validation rules are ultimately just method calls - you can do pretty much anything you want.  You are also not restricted to what's supplied in CSLA - you can write your own.  So if your team is suggesting the validation subsystem is simplistic, then I think they need to take a step back and re-evaluate the framework.

I think there's a deep misunderstanding of what Csla is meant to do, and how they would effectively use it.  It sounds like the offshore team is trying to look at the framework's code, without understanding its design goals and purpose, and shoehorn in their BRE, not knowing Csla objects are supposed to enforce the rules..  Kinda like picking Linq2Sql then blaming it when you can't connect to an Oracle database..

mbblum replied on Tuesday, December 22, 2009

Having watched Rocky's just released Core 3.8 Business Rules video, I highly recommend getting and watching it. It describes several options and approaches using the business/validation rules that deal with several of your issues. Among them are rule priorities, related property dependencies and, as noted in other replies, defining the severity of the failed rule (Error, Warning, Information in default CSLA).

rsbaker0 replied on Tuesday, December 22, 2009

I don't agree with overall message in the original post as we manage to enforce some very complicated business logic using the validation rule system.

That being said, some of these rules hit the database, and sometimes this is not inexpensive.

I think there would be some value in allowing rules to be explicitly run (not because of a property change) and having the result added/removed from the BrokenRulesCollection based on the outcome.

(Note that CSLA seems to contain the code to do this, but currently it is marked internal or private, so it's probably not hard at all to modify so you can do this)

I also think that it would be useful to be able to defer the execution of rules until just before an object is saved (or even have a formal mechanism for running rules server side) would be helpful. This would allow "expensive" validation to be delayed until the user is actually done editing the object.

RockfordLhotka replied on Wednesday, December 23, 2009

It is important to properly design your objects too. Remember that a good object design follows the use case (user scenario) not the database design.

So if you have a multi-step process, for example, you may have different objects for different steps. That is a type of rule, but it is embedded in the shape of the object graph, not as an explicit rule. The same is true for parent-child relationships - those are a type of rule, but that rule is intrinsically part of the object graph.

It is also the case that you can use severities. If many/most of your rules are warnings, then make them warnings. Windows Forms ErrorProvider can't help you there, but the WPF/SL PropertyStatus control is good, and there are CslaContrib controls for Windows Forms. Web Forms or MVC can display whatever you want to render, so a warning is no different from an error in terms of work effort for that UI style.

Remember that a rule sets the severity, so it can choose warning or error depending on the state of the object graph.

Finally, you can use priorities and short-circuiting. People often underestimate the capability of this feature, but it can be used to do some pretty amazing things, including making sure that some rules never run at all until the object state reaches some point where those rules make sense. Of course those rules could directly implement such a check too - but you can use e.StopProcessing to achieve a similar result.

Copyright (c) Marimer LLC