When/where should I act on the results of a session? #275
-
I've never worked with a rules engine before. Apologies for the naive question. I've been playing around with NRules for a few days. I've run the MissManners, and SimpleRules several times in the debugger. I'm struggling to imagine how (or where) a system would make use of the results. The examples show results through Console.WriteLine, from directly in the Then() of the rule. I would expect a production implementation to produce no output until the Fire() is complete. (Am I understanding that much?) My thought is that I need to query the session after all the rules have fired, and my code should interpret and act on the results only then. Is that right? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
@marked23 there is no prescribed way how to use the rules engine. It is not true that rules should not "produce output" until after the Fire method exits. You can have rules actually do something in the actions, and so essentially rules will affect externally-observable changes as they fire. |
Beta Was this translation helpful? Give feedback.
@marked23 there is no prescribed way how to use the rules engine. It is not true that rules should not "produce output" until after the Fire method exits. You can have rules actually do something in the actions, and so essentially rules will affect externally-observable changes as they fire.
But you can also use the engine similar to how you are describing it. You can just insert new facts or update existing facts in the session from the rules' actions, and then query the session at the end. This SO question I think demonstrates this approach well with a validation example: https://stackoverflow.com/questions/32554222/how-to-create-a-validation-rule-with-nrules