-
|
I don''t seem to be able to find any information about executors and dependencies. If I need to access an injected service from within an executor how do I go about this? EDIT: I am aware I can just pass them during construction! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
You've got it — constructor injection is the intended pattern. Executors are plain classes, so you pass dependencies through the constructor: public class MyExecutor : Executor
{
private readonly IMyService _service;
public MyExecutor(string id, IMyService service) : base(id)
{
_service = service;
}
}When registering workflows with the hosting layer, the builder.AddWorkflow("myWorkflow", (sp, key) =>
{
var myService = sp.GetRequiredService<IMyService>();
var executor = new MyExecutor("my-executor", myService);
return new WorkflowBuilder(executor).Build();
});This is in |
Beta Was this translation helpful? Give feedback.
-
|
Some related information here too: |
Beta Was this translation helpful? Give feedback.
You've got it — constructor injection is the intended pattern. Executors are plain classes, so you pass dependencies through the constructor:
When registering workflows with the hosting layer, the
AddWorkflowfactory delegate gives you access toIServiceProvider, so you can resolve services from DI there: