ILOG Rules for .NET User Guides > Rule Studio > Executing Rules > Creating an Engine and Executing a Ruleset

To embed the rule engine into an application, you only need to add a few lines to create a rule engine, add objects to the working memory, load a ruleset and execute it.

To integrate the rule engine into your application
// Create a rule engine instance.
RuleEngine engine = new RuleEngine();
 
// Select the ruleset to be used.
engine.RuleSet = new RuleProjectName();

To use ruleset parameters to present objects to the rule engine you use RuleEngine.SetParameterValue and RuleEngine.SetParameterValues.

// Set the ruleset parameters.
engine.SetParameterValue("parameterName", parameterValue);
engine.SetParameterValue("parameterName", parameterValue);
...
 
// Set the ruleflow on the engine.
engine.Ruleflow = engine.RuleSet.Ruleflows["package","ruleflow name"];
 
// Execute the business rules.
engine.Execute();
 
// Prepare the rule engine for another execution.
engine.RetractAll();
engine.Reset();

For example:

[C#]

using ILOG.Rules;
using CustomerBOM; // the business object model
...
RuleEngine engine = new RuleEngine();
engine.RuleSet = new CustomerRules();
Person billy = new Person(); // the object of interest
billy.name = "Billy";
engine.SetParameterValue("applicant", billy); // set the ruleset parameter
// Set the ruleflow - the Applications ruleflow in the CustomerRules package
engine.Ruleflow = engine.RuleSet.Ruleflows["CustomerRules", "Applications"];
engine.Execute();
engine.RetractAll();
engine.Reset();
 

[Visual Basic]

Imports ILOG.Rules
Imports CustomerBOM `the business object model
...
Dim engine As New RuleEngine
engine.RuleSet = New CustomerRules `the rules to execute
Dim billy As New Customer `the object of interest
billy.name = "Billy"
engine.SetParameterValue("applicant", billy)
`Set the ruleflow - the Applications ruleflow in the CustomerRules package.
engine.Ruleflow = engine.RuleSet.Ruleflows("CustomerRules", "Applications")
engine.Execute()
`Prepare the rule engine for another execution.
engine.RetractAll()
engine.Reset()

See Also

Rule Execution Modes | Retrieving Data and Events From the Engine | Setting an Exception Handler on the Engine Execution | Rule Application Sample | Reloading a Ruleset at Runtime