Using CSLA 4, say I have a BusinessObject 'Question' with properties for a name, a type (can be numeric, alphanum, listbox,..), a list of options (for listbox style questions where the user can select an answer from a list) and an answer.
Each Question object will need to have it's own ruleset defined when it created; numeric should only be numeric, perhaps within a certain range (depending on the question), some Questions may Required an answer. Moreover, the rules on a question should be able to change dependant on the answer provided to another question (Answer 1 is required but only if Answer 2 is less than 20) or change something like the available answer options on a displayed listbox-type question.
I am playing with using a gate rule that would determine the requirements of the specific question and be able define the rules from there, but I am struggling to get anything going.
Has anyone done anything like this, or able to offer direction?
You could be charting some new territory here, but in my mind this is the sort of thing you should be able to do in the new model.
I think you are on the right track with something similar to a gate rule - though rather than a gate, this rule would execute the correct rule(s) for the specific question.
Basically you'll need some way to associate rules with questions so your executor rule can execute them. In short, you'll have your own rules engine (in a way).
One thing you might consider doing, is to have a Rules property on your actual Question class. That way each instance of Question can have its own list of IBusinessRule objects.
Then you'd implement your Executor rule and attach it to Question, and when it runs it would get Target.Rules to get the list of rules to execute. You should be able to use rule chaining to execute them easily enough, because they'll all be IBusinessRule implementations.
I am most interested in how this works for you. As I say, it is certainly a scenario I intended to support, but to my knowledge you are the first to take a run at it.
Thanks Rocky, that gives me something to work with. I'm sure I'm going to have lots more questions around this though.
Copyright (c) Marimer LLC