GoRules.ZenEngine 2.0.1

dotnet add package GoRules.ZenEngine --version 2.0.1
                    
NuGet\Install-Package GoRules.ZenEngine -Version 2.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="GoRules.ZenEngine" Version="2.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="GoRules.ZenEngine" Version="2.0.1" />
                    
Directory.Packages.props
<PackageReference Include="GoRules.ZenEngine" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add GoRules.ZenEngine --version 2.0.1
                    
#r "nuget: GoRules.ZenEngine, 2.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package GoRules.ZenEngine@2.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=GoRules.ZenEngine&version=2.0.1
                    
Install as a Cake Addin
#tool nuget:?package=GoRules.ZenEngine&version=2.0.1
                    
Install as a Cake Tool

.NET Rules Engine

Business logic humans can read and machines can run. One copy of your rules: the owner reads it, every system runs it.

<img width="1280" alt="GoRules ZEN Engine" src="https://raw.githubusercontent.com/gorules/zen/master/.github/images/hero.png">

ZEN Engine is a cross-platform, open-source Business Rules Engine (BRE) written in Rust with native .NET bindings, alongside Node.js, Python, Go, Java and Kotlin. Decisions evaluate in microseconds, run identically on every platform, and are stored as portable JSON Decision Models (JDM). Loading the JSON is up to you: file system, database or service call.

Try it in the free Online Editor with a built-in simulator, or embed the open-source React JDM Editor in your own product. Learn more about the C# rules engine on the GoRules website.

Installation

dotnet add package GoRules.ZenEngine

Quick Start

using GoRules.ZenEngine;

// Create an engine and evaluate
var engine = new ZenEngine(loader: null, customNode: null);
var decision = engine.CreateDecision(new JsonBuffer(File.ReadAllBytes("my-decision.json")));
var context = new JsonBuffer("""{"input": 42}""");
var response = await decision.Evaluate(context, null);
Console.WriteLine(response.result);

Loader Configurations

The loader argument accepts either a callback (ZenLoader.Callback) or a loader configuration of a known type. With a configuration, decisions are pre-loaded and pre-compiled at engine creation for faster evaluations:

var fsEngine = new ZenEngine(loader: new ZenLoader.Filesystem("decisions"));
var zipEngine = new ZenEngine(loader: new ZenLoader.Zip(File.ReadAllBytes("decisions.zip")));
var cbEngine = new ZenEngine(loader: new ZenLoader.Callback(new FileLoader()));

Features

  • Decision Tables - Rule tables with first/collect hit policies
  • Expression Language - Built-in ZEN expression language with functions like sum(), filter(), map()
  • Custom Nodes - Extend the engine with custom node handlers
  • Tracing - Full execution trace for debugging and auditing
  • Cross-platform - Native libraries for Windows (x64), macOS (x64/ARM), Linux (x64/ARM)

Tracing

Enable tracing to inspect the execution of each node:

var options = new ZenEvaluateOptions(maxDepth: null, trace: true);
var decided = await decision.Evaluate(context, options);

foreach (var (nodeId, trace) in decided.trace!)
{
    Console.WriteLine($"{trace.name}: {trace.output}");
}

Expression Evaluation

Evaluate expressions directly without a decision file:

// One-off evaluation
var result = ZenUniffiMethods.EvaluateExpression(
    "sum(items) * multiplier",
    new JsonBuffer("{\"items\": [10, 20, 30], \"multiplier\": 2}")
);

// Compiled expression (reusable, better performance)
var expr = ZenExpression.Compile("a + b * 2");
var output = expr.Evaluate(new JsonBuffer("{\"a\": 1, \"b\": 10}"));
Console.WriteLine($"output: {output}");
expr.Dispose();

Custom Nodes

Extend the engine with custom logic:


using var myEngine = new ZenEngine(loader: new FileLoader(), customNode: new MyCustomNode());
var myResponse = await myEngine.Evaluate("custom.json", context, options);
Console.WriteLine(myResponse.result); 

// Custom node handler
class MyCustomNode : ZenCustomNodeCallback
{
    public Task<ZenEngineHandlerResponse> Handle(ZenEngineHandlerRequest request) =>
        Task.FromResult(new ZenEngineHandlerResponse(
            output: new JsonBuffer("""{"result": "custom"}"""),
            traceData: null
        ));
}

// Implement a loader to resolve decision files
class FileLoader : ZenDecisionLoaderCallback
{
    public Task<JsonBuffer?> Load(string key) =>
        Task.FromResult<JsonBuffer?>(new JsonBuffer(File.ReadAllBytes(key)));
}

Other platforms

License

MIT License

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.1 43 8/22/2026
2.0.0 71 8/20/2026
1.0.0-beta.14 41 8/18/2026
1.0.0-beta.13 55 8/18/2026
1.0.0-beta.3 330 6/29/2026
0.7.2 13,656 3/18/2026
0.7.0 118 3/15/2026
0.6.0 190 3/4/2026
0.5.0 185 2/25/2026