You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/index.md
+79Lines changed: 79 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,6 +28,8 @@ RulesEngine is a highly extensible library to build rule based system using C# e
28
28
-[Inbuilt Actions](#inbuilt-actions)
29
29
-[OutputExpression](#outputexpression)
30
30
-[Usage](#usage)
31
+
-[EvaluateRule](#evaluaterule)
32
+
-[Usage](#usage-1)
31
33
-[Custom Actions](#custom-actions)
32
34
-[Steps to use a custom Action](#steps-to-use-a-custom-action)
33
35
@@ -320,6 +322,83 @@ Call `ExecuteAllRulesAsync` with the workflowName, ruleName and ruleParameters
320
322
321
323
```
322
324
325
+
#### EvaluateRule
326
+
This action allows chaining of rules along with their actions. It also supports filtering inputs provided to chained rule as well as providing custom inputs
327
+
328
+
##### Usage
329
+
Define OnSuccess or OnFailure Action for your Rule:
330
+
```jsonc
331
+
{
332
+
"WorkflowName":"inputWorkflow",
333
+
"Rules": [
334
+
{
335
+
"RuleName":"GiveDiscount20Percent",
336
+
"Expression":"input1.couy == \"india\" AND input1.loyalityFactor <= 5 AND input1.totalPurchasesToDate >= 20000",
337
+
"Actions": {
338
+
"OnSuccess": {
339
+
"Name":"OutputExpression", //Name of action you want to call
340
+
"Context": { //This is passed to the action as action context
341
+
"Expression":"input1.TotalBilled * 0.8"
342
+
}
343
+
},
344
+
"OnFailure": { // This will execute if the Rule evaluates to failure
345
+
"Name":"EvaluateRule",
346
+
"Context": {
347
+
"WorkflowName":"inputWorkflow",
348
+
"ruleName":"GiveDiscount10Percent"
349
+
}
350
+
}
351
+
}
352
+
},
353
+
{
354
+
"RuleName":"GiveDiscount10Percent",
355
+
"SuccessEvent":"10",
356
+
"ErrorMessage":"One or more adjust rules failed.",
357
+
"ErrorType":"Error",
358
+
"RuleExpressionType":"LambdaExpression",
359
+
"Expression":"input1.couy == \"india\" AND input1.loyalityFactor <= 2 AND input1.totalPurchasesToDate >= 5000 AND input2.totalOrders > 2 AND input2.noOfVisitsPerMonth > 2",
360
+
"Actions": {
361
+
"OnSuccess": {
362
+
"Name":"OutputExpression", //Name of action you want to call
363
+
"Context": { //This is passed to the action as action context
364
+
"Expression":"input1.TotalBilled * 0.9"
365
+
}
366
+
}
367
+
}
368
+
}
369
+
]
370
+
}
371
+
```
372
+
Call `ExecuteActionWorkflowAsync` with the workflowName, ruleName and ruleParameters
Console.WriteLine(result.Output); //result.Output contains the evaluated value of the action
376
+
```
377
+
378
+
In the above scenario if `GiveDiscount20Percent` succeeds, it will return 20 percent discount in output. If it fails, `EvaluateRule` action will call `GiveDiscount10Percent` internally and if it succeeds, it will return 10 percent discount in output.
379
+
380
+
EvaluateRule also supports passing filtered inputs and computed inputs to chained rule
381
+
```jsonc
382
+
"Actions": {
383
+
"OnSuccess": {
384
+
"Name":"EvaluateRule",
385
+
"Context": {
386
+
"WorkflowName":"inputWorkflow",
387
+
"ruleName":"GiveDiscount10Percent",
388
+
"inputFilter": ["input2"], //will only pass input2 from existing inputs,scopedparams to the chained rule
389
+
"additionalInputs":[ // will pass a new input named currentDiscount with the result of the expression to the chained rule
390
+
{
391
+
"Name":"currentDiscount",
392
+
"Expression":"input1.TotalBilled * 0.9"
393
+
}
394
+
]
395
+
}
396
+
}
397
+
}
398
+
399
+
```
400
+
401
+
323
402
### Custom Actions
324
403
RulesEngine allows registering custom actions which can be used in the rules workflow.
<Description>Rules Engine is a package for abstracting business logic/rules/policies out of the system. This works in a very simple way by giving you an ability to put your rules in a store outside the core logic of the system thus ensuring that any change in rules doesn't affect the core system.</Description>
0 commit comments