Extension methods and DI #102
Unanswered
josephpdunne
asked this question in
Q&A
Replies: 1 comment 5 replies
-
Hi, I believe you are looking for using an instance of RuleExtensions class which can be initialised via DI. If that is the case, you can pass an instance of RuleExtensions as ruleParameter. //In you execution code
var ruleExtensionInstance = new RuleExtensions(_service);//or get it from DI
var extensionParam = new RuleParameter("ruleExtensions",ruleExtensionInstance);
var input1 = new RuleParameter("input1",input1);
var results = await rulesEngine.ExecuteAllRulesAsync("myWorkflow", extensionParam, input1); Let me know if this answers your question. |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I am using an Extension method for a rule which in turn needs to use data services.
Asp.Net core Api application with standard DI for services etc.
Some pseudo code
Having to call RuleExtensions.Configure(_service) to add the scoped/transient service smells.
Is there any pattern to follow that I missed?
I am aware of service locator etc. and trying to avoid any anti-pattern.
One idea is a custom middleware method to set it but again, kinda smells.
Thanks,
Joe
Beta Was this translation helpful? Give feedback.
All reactions