Skip to content
Discussion options

You must be logged in to vote

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 AddWorkflow factory delegate gives you access to IServiceProvider, so you can resolve services from DI there:

builder.AddWorkflow("myWorkflow", (sp, key) =>
{
    var myService = sp.GetRequiredService<IMyService>();
    var executor = new MyExecutor("my-executor", myService);
    return new WorkflowBuilder(executor)

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by mvp013
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants