OLAX.InnovativeLab.RulesEngine 1.0.2

dotnet add package OLAX.InnovativeLab.RulesEngine --version 1.0.2
                    
NuGet\Install-Package OLAX.InnovativeLab.RulesEngine -Version 1.0.2
                    
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="OLAX.InnovativeLab.RulesEngine" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OLAX.InnovativeLab.RulesEngine" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="OLAX.InnovativeLab.RulesEngine" />
                    
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 OLAX.InnovativeLab.RulesEngine --version 1.0.2
                    
#r "nuget: OLAX.InnovativeLab.RulesEngine, 1.0.2"
                    
#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 OLAX.InnovativeLab.RulesEngine@1.0.2
                    
#: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=OLAX.InnovativeLab.RulesEngine&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=OLAX.InnovativeLab.RulesEngine&version=1.0.2
                    
Install as a Cake Tool

OLAX.InnovativeLab.RulesEngine

A lightweight, flexible rules engine wrapper for .NET 8+.

This package provides a file-based storage implementation for the Microsoft RulesEngine, designed for seamless integration into ASP.NET Core applications with built-in Dependency Injection support.


Features

  • JSON File Storage: Manage workflow definitions easily using local JSON files.
  • Dependency Injection Ready: Native IServiceCollection extension methods for quick setup.
  • Custom Functions Support: Execute complex business logic by injecting your own C# services into rule expressions.
  • Scoped Parameters: Full support for scoped parameters in rule execution.
  • Caching: Built-in caching for workflow definitions to ensure high performance.

Installation

Install the package from your NuGet feed:

dotnet add package OLAX.InnovativeLab.RulesEngine

Getting Started

1. Configure Services (Program.cs)

Register the rules engine in your application startup. You can point it to your storage directory and register any custom types you intend to use within your rules.

using OLAX.InnovativeLab.RulesEngine.DI;

var builder = WebApplication.CreateBuilder(args);

// Define where your JSON rule files are located
var rulesPath = builder.Configuration.GetValue<string>("Storage:JsonFilePath") 
               ?? AppContext.BaseDirectory;

builder.Services.AddOlaxRulesEngine(
    configureEngine: opt =>
    {
        opt.WorkflowCacheTtl = TimeSpan.FromMinutes(5); // Cache duration
        opt.EnableScopedParams = true;

        // IMPORTANT: Register types here to use their methods in rule expressions
        // opt.CustomTypes.Add(typeof(Inventory.API.Services.CustomRuleFunctionsService));
    },
    configureStore: store =>
    {
        store.BasePath = rulesPath;
        store.FolderName = "Rules"; // Subfolder name
    });

2. Create a Rule File

Create a JSON file (e.g., OrderValidation.json) in your storage folder:

[
  {
    "WorkflowName": "OrderValidation",
    "Rules": [
      {
        "RuleName": "CheckStock",
        "ErrorMessage": "Insufficient stock available.",
        "Expression": "CurrentStock < RequestedQuantity",
        "SuccessEvent": "StockLow"
      }
    ]
  }
]

3. Execute Rules

Inject IRulesEngineService into your controller or service and execute the workflow.

public class OrderController : ControllerBase
{
    private readonly IRulesEngineService _rulesEngine;

    public OrderController(IRulesEngineService rulesEngine)
    {
        _rulesEngine = rulesEngine;
    }

    [HttpPost("validate")]
    public async Task<IActionResult> ValidateOrder(OrderRequest request)
    {
        var inputs = new Dictionary<string, object>
        {
            ["CurrentStock"] = 50,
            ["RequestedQuantity"] = request.Quantity
        };

        var result = await _rulesEngine.ExecuteRuleAsync(
            "OrderValidation",
            "CheckStock",
            inputs
        );

        if (result.IsSuccess)
        {
            return BadRequest(result.ErrorMessage);
        }

        return Ok("Order Validated");
    }
}

Advanced Usage: Custom Functions

You can execute complex C# logic inside your JSON rules (e.g., calculating dynamic tax or calling external validators).

1. Define & Register Your Service

opt.CustomTypes.Add(typeof(MyCustomFunctions));

2. Inject the Instance at Runtime

var inputs = new Dictionary<string, object>
{
    ["unitPrice"] = 100,
    ["taxRate"] = 0.15,
    ["customFunctions"] = _myCustomFunctionsService
};

await _rulesEngine.ExecuteRuleAsync(
    "TaxWorkflow",
    "CalculateTax",
    inputs
);

3. Call it in JSON

{
  "RuleName": "CalculateTax",
  "Actions": {
    "OnSuccess": {
      "Name": "OutputExpression",
      "Context": {
        "Expression": "customFunctions.CalculateTax(unitPrice, taxRate)"
      }
    }
  }
}

License

Proprietary License (Freeware)

Copyright (c) 2026 OLAX Innovative Lab. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software package, to use the Software in personal, non-commercial, and commercial applications.

You may NOT modify, reverse engineer, or disassemble the Software.
You may NOT redistribute the source code.

See the LICENSE.txt file in the package for full license details.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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.

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
1.0.2 336 2/9/2026
1.0.1 117 2/9/2026
1.0.0 119 1/23/2026