Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Sergiy Nikolayev
    @snikolayev
    @yashad.singh_gitlab if you want to use rule dependencies (which are resolved at rules run time), you need to implement and supply an IDependencyResolver (see https://github.com/NRules/NRules/wiki/Rule-Dependencies). Another approach is to inject dependencies into rules classes at rules instantiation time. In this case you need to implement IRuleActivator (see https://github.com/NRules/NRules/wiki/Fluent-Rules-Loading#Rule-Activation). When you implement one or both of these interfaces, you can simply just forward resolution requests to your existing service container.
    Another NRules user I believe took a stab at implementing an integration project between NRules and .net core container: https://github.com/cloudb0x/NRules.Integration.AspNetCore
    yashad singh
    @yashad.singh_gitlab
    image.png

    @snikolayev Is it possible to consume scoped services in MyRule (: Rule)? Currently it only work with Singleton service ( services.AddSingleton<IServiceTest, ServiceTest>(); ).

    When I tried scoped services ( services.AddScoped<IServiceTest, ServiceTest>(); ) it threw an error as shown in the image above.

    Sergiy Nikolayev
    @snikolayev
    @yashad.singh_gitlab you cannot use scoped services with rule activation, because rules are instantiated once during the application lifetime. But you should be able to use them with the runtime rules dependencies, via IDependencyResolver. When implementing the resolver, forward the resolution requests to the scoped service provider, instead of the root service provider. This also means you would have to create a new session per scope, create a dependency resolver for that scope and set it on that session.
    yashad singh
    @yashad.singh_gitlab
    Thanks @snikolayev ... It worked. Thanks a lot.
    yashad singh
    @yashad.singh_gitlab
    image.png
    @snikolayev How can I make this call awaitable in above code in the image? Is it possible?
    Sergiy Nikolayev
    @snikolayev
    @yashad.singh_gitlab no, async actions are not supported
    yashad singh
    @yashad.singh_gitlab
    image.png
    @snikolayev I am creating a dynamic Rule as shown in above image. But I did not find a way to load that rule in RuleRespository.
    Sergiy Nikolayev
    @snikolayev
    @yashad.singh_gitlab if you are creating rules dynamically, you don't need RuleRepository, as that's only used with the rules defined using C# DSL. When using RuleBuilder, you are getting back IRuleDefinitions, and you can feed them directly to RuleCompiler.Compile method.
    ByteCode2408
    @ByteCode2408
    Hi! I don't know if this has been discussed before, but I would like to know if the rule engine will be a correct fit in a Domain Driven Design project. Use case: I have a Payment domain object and a set of business rules: if Payment.Amount is less than x, then process the payment using IExternalGateway1, if Amount between x and y, then try IExternalGateway2 if available, else retry only once with IExternalGateway1, if Amount > y, try only IExternalGateway3
    Sergiy Nikolayev
    @snikolayev
    Hi @ByteCode2408 - I think many of the concepts and principles of DDD are fairly universal whether you are using a rules engine or not: ubiquitous language, bounded contexts, core domain and generic subdomains, etc. I also think you should fully invest into a rich domain model, if you are subscribing to DDD. Where the rules engine will add a new spin, IMO, is how you encode the logic that under DDD normally goes into services. Essentially, the way I'm thinking about the relationship between the domain model and rules is in terms of the type of logic they are encoding. A domain model of course encodes the structure of the domain in a form of entities and their relations. A domain model usually also encodes fairly static slowly changing logic, like invariants imposed by the domain. Rules on the other hand encode volatile logic - policies - that change frequently, or logic external to the core domain. In your case, you would model the Payment domain using rich entities. But then a service, say a PaymentGateway as an example, may actually spin up an NRules Session (from previously compiled payment rules), insert the Payment fact into that session (along with other items in the payment aggregate, using DDD terminology) and have those rules dispatch the payment to the external gateway.
    ByteCode2408
    @ByteCode2408
    Cool, that's what I was thinking, thank you for clarification!
    Jaliya Udagedara
    @jaliyaudagedara
    @snikolayev, we have started using NRules and it's good stuff. Have a question, can I please know how we can Yield a new fact for Forward Chaining when creating rules dynamically.
    Benoit Provost
    @namtar1447
    Hello @jaliyaudagedara, from my very limited experience, when you define your action Expression, nothing prevents you from using ctx.InsertLinked() which should behave like Yield in terms of retraction.
    1 reply
    Benoit Provost
    @namtar1447

    I also happen to have a question, I'm working on a project that requires going through rules and at some point having several choices (2-30 but possibly one choice leads to more choices down the line). I would like to be able to let the engine start from the current state and "trying" multiple solutions. I'm trying to figure out a way a simple and hopefully efficient way to do this. Here's what I experimented with/considered so far:

    1) Considered using LinkedFacts, and while that handles new facts retraction, updates to existing facts wouldn't be reverted. So make a log of updates and revert manually?
    2) Deep-copy all facts, make choice, continue execution. Once run is over, retract all, insert all fact copies, make new choice, repeat.
    3) Deep-copy all facts, halt current session, create new session for each choice, starting with the fact copies.

    I have the impression I'm missing a clever way to use the framework to help me. Additionally, doing this in a way where I can leverage already calculated fact combinations would be great as there are combinations that would be repeated.

    The reason I'm trying to use NRules for this is that new and updated facts tend to trigger a limited number of rules and fact changes. For reference the "scale" I'm working with is along the lines of ~50-200 facts and probably ~50-200 rules.

    Thanks!

    1 reply
    Pravinskamane
    @Pravinskamane
    Hi, Is there a way to configure the Rules in database, and pull them to load the rules. Also how can we do some logging from the rule methods .
    4 replies
    Pravinskamane
    @Pravinskamane
    Hi, Thanks. Is there a way in which we can return any value from the Rule definition to the place of session.Fire()?
    1 reply
    Pravinskamane
    @Pravinskamane
    Is there a way to set ordering sequence on Rules. For example to execute rules in a particular sequence?
    2 replies
    Têng Ûi
    @tingwei628
    Hi @snikolayev , I wonder how to do rule dependency injection with Unity container.
    3 replies
    Pavel Moskalevich
    @happanda
    Hi there. Is there a way to write rules that react specifically to Fact creation vs Fact update? Lets say, Fact is a class with one bool variable. I'd like one Rule that will .Do something when such Fact is created, .Undo something when Fact is retracted. And a different rule to fire when this bool value changes only for already existing Facts. Is it possible?
    2 replies
    Pavel Moskalevich
    @happanda

    Thanks for the previous answer. Now I'm trying to figure out how to deal with ActionTrigger. Consider the following CODE
    When I run it, I get the expected output:

    Activated Baz
    Reactivated Zab
    Deactivated Zab

    But if I remove Action with ActionTrigger.Reactivated, only the first line is printed. The engine doesn't react to retraction. Why is that happening?

    2 replies
    Maarten Louage
    @mlouage
    Hello, I'm a new to this powerful library! I have a question which I did not find the answer in the documentation: is it possible to inject a dependency into a rule? I have rules on my domain model like if Country is not in the list of allowed countries to travel to, set a warning. That list of allowed countries is managed through a service which calls an HTTP endpoint. How can I inject this service into the rule?
    6 replies
    Argiris Gerogiannis
    @ageroh
    Hi all,
    Have anybody used NRules.Language before ?
    Adrian
    @adriangonzalez
    @ageroh I haven't used it, but I am going to be trying it out this weekend :)
    Charanpreet Singh
    @charanpreetsinghda
    Hi there - is there a way to skip following rules within a ruleset as soon as a rule in that ruleset failed?
    6 replies
    morisamon
    @morisamon
    Hey everyone, is there a way to add dependency and option to resolve by rule builder and not by class definition?
    Best regards,
    Thank you :)
    1 reply
    davideps
    @davideps
    I'm looking for a rules engine and have two questions: (1) How well does nrules scale in terms of number of rules and facts? (2) would implementing backward changing be difficult? (I assume yes since it has not been done yet, but maybe there is little demand?)
    3 replies
    davideps
    @davideps
    ("chaining" not "changing")
    wangadeketan
    @wangadeketan
    @snikolayev How to log a rule if the rule condition failed ?
    10 replies
    karthik sundar
    @karthikn92-sundar
    Hello everyone, I want to use groupby to get the count and with the count I've to add some other logics. Is this possible ?
    1 reply
    wangadeketan
    @wangadeketan
    @snikolayev what is the next release date of Nrules ?
    Sergiy Nikolayev
    @snikolayev
    @wangadeketan definitely releasing new version this year. Hopefully much sooner than the EOY
    wangadeketan
    @wangadeketan
    Great
    christiansent
    @christiansent
    Hi,
    Hi, I have NRules working in an application, where the rules are in C#. The design has changed requiring the rules be moved to a database. I added Rules.Language, and it is working. Is there a way to set the priority number from the text rule? Also, when I included Console.WriteLine as in the example, I got a runtime error. I added "using System" to the rule - did not help. Works fine without this.
    2 replies
    christiansent
    @christiansent
    Possible to expand the GitHub example to show how to handle Not?
    1 reply
    christiansent
    @christiansent
    Figured out the NOT: not Attribute_DOUBLE(sr => sr.NameIs("SHOPRATE"));
    wangadeketan
    @wangadeketan
    @snikolayev Hi,
    How to call a multiple rules at one time from diff location with diff data ?
    11 replies
    christiansent
    @christiansent
    Hi Sergiy. Been using NRules for a couple years. In one application recently moved from C# to loading from database. Worked well until now, have a problem that I am having trouble root causing. Here is exception trace. Exception has occurred: CLR/System.ArgumentException
    An exception of type 'System.ArgumentException' occurred in System.Private.CoreLib.dll but was not handled in user code: 'Array may not be empty.'
    at System.DefaultBinder.SelectMethod(BindingFlags bindingAttr, MethodBase[] match, Type[] types, ParameterModifier[] modifiers)
    at NRules.RuleSharp.ParserContext.FindExtensionMethod(Type type, String methodName, Type[] argumentTypes)
    at NRules.RuleSharp.PrimaryExpressionBuilder.Method(String methodName, Type type, Expression instance, List1 argumentsList) at NRules.RuleSharp.PrimaryExpressionBuilder.Method(List1 argumentsList)
    at NRules.RuleSharp.ExpressionParser.VisitPrimary_expression(Primary_expressionContext context)
    at NRules.RuleSharp.Parser.RuleSharpParser.Primary_expressionContext.AcceptTResult
    at Antlr4.Runtime.Tree.AbstractParseTreeVisitor1.Visit(IParseTree tree) at NRules.RuleSharp.ExpressionParser.VisitUnary_expression(Unary_expressionContext context) at NRules.RuleSharp.Parser.RuleSharpParser.Unary_expressionContext.Accept[TResult](IParseTreeVisitor1 visitor)
    at Antlr4.Runtime.Tree.AbstractParseTreeVisitor1.Visit(IParseTree tree) at NRules.RuleSharp.ExpressionParser.VisitMultiplicative_expression(Multiplicative_expressionContext context) at NRules.RuleSharp.Parser.RuleSharpParser.Multiplicative_expressionContext.Accept[TResult](IParseTreeVisitor1 visitor)
    at Antlr4.Runtime.Tree.AbstractParseTreeVisitor1.Visit(IParseTree tree) at NRules.RuleSharp.ExpressionParser.VisitAdditive_expression(Additive_expressionContext context) at NRules.RuleSharp.Parser.RuleSharpParser.Additive_expressionContext.Accept[TResult](IParseTreeVisitor1 visitor)
    at Antlr4.Runtime.Tree.AbstractParseTreeVisitor1.VisitChildren(IRuleNode node) at NRules.RuleSharp.Parser.RuleSharpParserBaseVisitor1.VisitShift_expression(Shift_expressionContext context)
    at NRules.RuleSharp.Parser.RuleSharpParser.Shift_expressionContext.AcceptTResult
    at Antlr4.Runtime.Tree.AbstractParseTreeVisitor1.Visit(IParseTree tree) at NRules.RuleSharp.ExpressionParser.VisitRelational_expression(Relational_expressionContext context) at NRules.RuleSharp.Parser.RuleSharpParser.Relational_expressionContext.Accept[TResult](IParseTreeVisitor1 visitor)
    at Antlr4.Runtime.Tree.AbstractParseTreeVisitor1.Visit(IParseTree tree) at NRules.RuleSharp.ExpressionParser.VisitEquality_expression(Equality_expressionContext context) at NRules.RuleSharp.Parser.RuleSharpParser.Equality_expressionContext.Accept[TResult](IParseTreeVisitor1 visitor)
    at Antlr4.Runtime.Tree.AbstractParseTreeVisitor1.Visit(IParseTree tree) at NRules.RuleSharp.ExpressionParser.VisitAnd_expression(And_expressionContext context) at NRules.RuleSharp.Parser.RuleSharpParser.And_expressionContext.Accept[TResult](IParseTreeVisitor1 visitor)
    at Antlr4.Runtime.Tree.AbstractParseTreeVisitor1.Visit(IParseTree tree) at NRules.RuleSharp.ExpressionParser.VisitExclusive_or_expression(Exclusive_or_expressionContext context) at NRules.RuleSharp.Parser.RuleSharpParser.Exclusive_or_expressionContext.Accept[TResult](IParseTreeVisitor1 visitor)
    at Antlr4.Runtime.Tree.AbstractParseTreeVisitor1.Visit(IParseTree tree) at NRules.RuleSharp.ExpressionParser.VisitInclusive_or_expression(Inclusive_or_expressionContext context) at NRules.RuleSharp.Parser.RuleSharpParser.Inclusive_or_expressionContext.Accept[TResult](IParseTreeVisitor1 visitor)
    at Antlr4.Runtime.Tree.AbstractParseTreeVisitor1.Visit(IParseTree tree) at NRules.RuleSharp.ExpressionParser.VisitConditional_and_expression(Conditional_and_expressionContext context) at NRules.RuleSharp.Parser.RuleSharpParser.Conditional_and_expressionContext.Accept[TResult](IParseTreeVisitor1 visitor)
    2 replies
    Error happens when repository.LoadText is called
    christiansent
    @christiansent
    I figured it out, was error in function call on Fact
    1 reply
    christiansent
    @christiansent
    I had a function on the Fact object (Attribute_BASE with derived classes) with two parameters. The second was optional. I think that not supplying the optional second caused a problem. The problem disappeared when I split the function into two: 1) one parameter, 2) two parameters (second required, not optional). Hope this helps
    John Coleman
    @JohnSColeman
    Hi, what is the rul equivalent of this drl:
    import model.LineItem;
    import model.Brand;
    import model.Market;
    import model.Seller;
    global java.util.List coupons;
    
    rule "Rule 1"
        when
            exists LineItem(category == "PC", market in (Market.MARKETPLACE1), brand in (Brand.ACER))
        then
            coupons.add("#PC0001");
    end
    4 replies
    Sergiy Nikolayev
    @snikolayev
    PSA - moving forward, please ask questions related to NRules.RuleSharp, rul files, NRules.Language here: https://gitter.im/NRules/NRules.Language
    And keep asking questions about NRules fluent C# DSL and NRules runtime here in this forum
    1 reply
    karthik sundar
    @karthikn92-sundar
    Is there a way to dynamically change the right hand side values.
    For eg. When()
    .Query(() => currentCartItem, p => p
    .Match<ShoppingCartItem>(
    c => (c.Status != null && (c.Status.ToUpper() == "OPEN" || c.Status.ToUpper() == "P" || c.Status.ToUpper() == "NULL")) && c.NumberOfUniqueParts > '25'
    )
    .Collect()
    .Where(c => c.Any()));
                Then()
                    .Do(ctx => SendEmailNotification(currentCartItem));
    1 reply
    i want to change the NumberOfUniqueParts value from 25 to 50