Skip to content

Allow dependency injection on Workflow - #576

Merged
danielgerlag merged 2 commits into
danielgerlag:masterfrom
glucaci:dev
Jun 21, 2020
Merged

Allow dependency injection on Workflow#576
danielgerlag merged 2 commits into
danielgerlag:masterfrom
glucaci:dev

Conversation

@glucaci

@glucaci glucaci commented Jun 8, 2020

Copy link
Copy Markdown
Collaborator

It will be very usefull to can inject services/configuration into Workflow directly.

Example:

public class SampleWorkflow : IWorkflow<SampleRequest>
{
    private readonly IOptions<WorkflowOptions> _options;

    public SampleWorkflow(IOptions<WorkflowOptions> options)
    {
        _options = options;
    }

    public string Id => nameof(SampleWorkflow);

    public int Version => 1;

    public void Build(IWorkflowBuilder<SampleRequest> builder)
    {
        builder
            .StartWith(context => ExecutionResult.Next())
            .Then<SampleStep>()
                .Input(step => step.Request, data => data)
                .OnError(WorkflowErrorHandling.Retry, _options.Value.RetryInterval);
    }
}

@glucaci
glucaci marked this pull request as ready for review June 8, 2020 13:54
@vaclavpfeifer

Copy link
Copy Markdown

I think it is already possible to register a WF using DI.
RegisterWorkflow(serviceProvider.GetService());

@glucaci

glucaci commented Jun 8, 2020

Copy link
Copy Markdown
Collaborator Author

Where is this method?
These are the only two methods of RegisterWorkflow

public interface IWorkflowController
{
    ...
    void RegisterWorkflow<TWorkflow>() where TWorkflow : IWorkflow, new();

    void RegisterWorkflow<TWorkflow, TData>()
      where TWorkflow : IWorkflow<TData>, new()
      where TData : new();
    ...
}

@glucaci

glucaci commented Jun 8, 2020

Copy link
Copy Markdown
Collaborator Author

Ok, I saw... you mean on the IWorkflowRegistry.
We used till now the IWorkflowHost to register the workflows because you need also to start it afterwards. It's pretty confusing registering workflows because this method is everywhere, IWorkflowHost , IWorkflowController, IWorkflowRegistry

@glucaci

glucaci commented Jun 9, 2020

Copy link
Copy Markdown
Collaborator Author

The solution from IWorkflowRegistry implies that you have to new manually the Workflow which is not very clean, because using the IServiceProvider is not an option

@glucaci

glucaci commented Jun 11, 2020

Copy link
Copy Markdown
Collaborator Author

@danielgerlag what do you think? could we merge this?

@danielgerlag danielgerlag left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, can you increment the minor version of any libraries that need to be published?

@glucaci

glucaci commented Jun 18, 2020

Copy link
Copy Markdown
Collaborator Author

Done.
Only Core right? Why are you not using same version for all the packages?

@danielgerlag

Copy link
Copy Markdown
Owner

We use the same major version, but allow the minor and patch to vary.

@danielgerlag
danielgerlag merged commit 0ec90bc into danielgerlag:master Jun 21, 2020
@IvanJosipovic

Copy link
Copy Markdown
Contributor

@danielgerlag Do you have an ETA when this code will be released?

Thank you!

@danielgerlag

Copy link
Copy Markdown
Owner

ah, it looks like it didn't deploy because the PackageVersion was not incremented, I'll sort that out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants