New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

EasyRules

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

EasyRules

The simple, stupid rules engine for .NET

Source
nugetNuGet
Version
1.0.3
Version published
Maintainers
1
Created
Source

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.

Keywords

rules-engine

FAQs

Package last updated on 21 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts