danielgerlag / workflow-core

Lightweight workflow engine for .NET Standard
MIT License
5.4k stars 1.2k forks source link

[Proposal] Add IServiceScope support so that steps can get same service instances from this scope #1231

Open ling921 opened 10 months ago

ling921 commented 10 months ago

Is your feature request related to a problem? Please describe.

I have a scoped service IMyService and get an IMyService instance from a scope, I hope that all steps will obtain the same IMyService instance when the workflow is running. This can prevent the services between multiple workflows from interfering with each other.

Describe the solution you'd like

Add a method to IWorkflowController called StartWorkflowWithScope, which accept an additional parameter IServiceScope, and then save it in WorkflowInstance

Describe alternatives you've considered

None

Additional context

I would like to make a pull request for this.

vladimir-kovalyuk commented 8 months ago

From my perspective what you would like to achieve is not guaranteed within the resilient long running process. The host may execute the half of steps then get restarted and continue executing the rest of steps. So you can not rely on the WFC hoping that it would provide the same IMyService for all steps. You may inject IServiceScope and IServiceScopeFactory into your step. Maybe these interfaces being injected would help you with your needs? BTW, not sure Workflow-Core project is alive.