EasyRules 1.0.3

dotnet add package EasyRules --version 1.0.3                
NuGet\Install-Package EasyRules -Version 1.0.3                
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="EasyRules" Version="1.0.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EasyRules --version 1.0.3                
#r "nuget: EasyRules, 1.0.3"                
#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.
// Install EasyRules as a Cake Addin
#addin nuget:?package=EasyRules&version=1.0.3

// Install EasyRules as a Cake Tool
#tool nuget:?package=EasyRules&version=1.0.3                

Easy Rules: The simple, stupid rules engine for .NET

What is Easy Rules?

Easy Rules is a .NET port of the Easy Rules Java-based rules engine, which was inspired by an article called "Should I use a Rules Engine?" by Martin Fowler in which he states:

You can build a simple rules engine yourself. All you need is to create a bunch of objects with conditions and actions, store them in a collection, and run through them to evaluate the conditions and execute the actions.

This is exactly what Easy Rules does, it provides the Rule abstraction to create rules with conditions and actions, and the RulesEngine API that runs through a set of rules to evaluate conditions and execute actions.

Core features

  • Lightweight library and easy to learn API
  • POCO based development with an annotation programming model
  • Useful abstractions to define business rules and apply them easily with .NET
  • The ability to create composite rules from primitive ones
  • The ability to define rules using an Expression Language ← Maybe Later

Example

1. First, define your rule...

Either in a declarative way using annotations:
[Rule(Name = "weather rule", Description = "if it rains then take an umbrella")]
public sealed class WeatherRule
{
    [Condition]
    public bool ItRains([Fact("rain")] bool rain) => rain;
    
    [Action]
    public void TakeAnUmbrella() {
        Console.WriteLine("It rains, take an umbrella!");
    }
}
Or in a programmatic way:
var weatherRule = new Rule(
    name: "weather rule",
    description: "if it rains then take an umbrella",
    condition: f => f.True(rain),
    action: _ => Console.WriteLine("It rains, take an umbrella!"));

2. Then, fire it!

    // define facts
    var facts = new Facts()
    {
        { "rain", true }
    };

    // define rules
    var weatherRule = ...
    var rules = new Rules()
    {
        weatherRule
    };

    // fire rules on known facts
    var rulesEngine = new DefaultRulesEngine();
    rulesEngine.Fire(rules, facts);

This is the hello world of Easy Rules. You can find other examples on the original Easy Rules Wiki.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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.3 73 12/21/2024
1.0.2 125 6/7/2024
1.0.1 133 4/11/2024
1.0.0 130 4/10/2024 1.0.0 is deprecated because it has critical bugs.