Replies: 2 comments
-
Hi @Zefek , I am interested in adding a feature/functionality if it can help simplify or enhance the RulesEngine. From what I understand, Specification is sort of an Our rule expression acts as a validator and we have actions to invoke when rule succeeds or fails. We also have an inject workflow feature which can be used to collect all specifications from a single place. In a way, I feel RulesEngine already covers the mentioned specification pattern. Please correct me if I am missing out on something. |
Beta Was this translation helpful? Give feedback.
-
Hello @abbasc52 I try to describe more precise what I meant.
I have business condition to check if order customer has allowed products on Order. Customer has allowed product collection. There exist two repositories - Order and Customer - each for entity in domain model meaning. So, how to do checks? Idea is that I load Order by OrderId to order variable and I load Customer by order.CustomerId to customer variable and send order and customer to RuleEngine as two input. Expression can be written in json as well as. Problem is how to check RuleEngine that expression is valid, there is not type error or some similar issue? Can by any tests performed before deployment? What would I like to do? I have similar framework about Specification as RuleEngine. But there is difference. Each condition is programmed. It means in code there is property:
It is similar as you meant to alias. But it is programmed, and I can create unit test to it. I have experience that I developed application with more than 200 specifications. Specifications were easy but in interval (to check if something is in interval) specifications there were many errors with identify interval bounder. It was starting point to learn unit testing for me :) Specification can be combined by & | ! operators and it is used by Rule which hold some business action or error message. It is similar to RulesEngine. But ErrorMessage can be created by Func<T, string> expression. It means there is method which can create more complex messages like to get some additional information from database or another data store. I know there is reason to use RulesEngine when I want to create business without coding. But I think there can be reason to some coding because of unit testing. But I think it would be very nice to combinate coded specification with json configuration as RulesEngine provides. Reason for that I see each specification can be tested and it can be important for more complex specifications and RulesEngine provides that specification can be used as you need by configuration. Do you see any possibility how to work with this approach in RulesEngine? |
Beta Was this translation helpful? Give feedback.
-
Hello,
I spent many times to improve how to apply with business rules. I read about Specification pattern and I developed small "engine" to work with them. It is very similar to Rules Engine. Foundation of Specification pattern is Specification which is bool "expression" - in implementation it is anonymous function (Func<T, bool> or Func<T, Task>). Specification is not rule, it is business condition which can be used in different rules. Specification override operator AND (&), OR (|) and negation (!). It means specification can be combined by these operators together to create larger and more complex business condition.
Main advantage of Specification is that each condition has name which is in relation with business. Second advantage is that each specification can be tested with small unit test.
Specification is used by rule. I have two types of rule - Validation and Action. Validation rule takes specification and error message. It checks input entity against specification and when specification is false, error message is used by validator to result. It means there is (Input entity)Validator which has rule collection and it checks input entity against all rules and gives some result.
Action rule takes specification and some Action (Action or Func<T, Task>>). There is ActionEvaluator which takes input entity and checks it against all Action rules and if specification of rule is true then action is invoked.
Disadvantage is that Specification must be implemented if not exists. But if specification exists it can be tested by unit test and can be used in each rule.
I developed small engine that configuration can be stored in json. Validator or ActionEvaluator has all rules defined in ctor implementation. But when Validator or ActionEvaluator is adding some rule can be ignored when name of rule is not in configuration (or it is disabled in configuration) for current Validator or ActionEvaluator.
So I think it is very similar to Rules Engine. I think it would be interesting to expand Rules engine with Specification pattern. I would like to be contributor of this idea. But what are you thinking about it? Is it good way to add Specification pattern into Rules Engine?
Thank you.
Beta Was this translation helpful? Give feedback.
All reactions