@@ -22,12 +22,10 @@ public class WorkflowExecutor : IWorkflowExecutor
22
22
private readonly ICancellationProcessor _cancellationProcessor ;
23
23
private readonly ILifeCycleEventPublisher _publisher ;
24
24
private readonly WorkflowOptions _options ;
25
- private readonly IStepExecutor _stepExecutor ;
26
- private readonly IWorkflowMiddlewareRunner _middlewareRunner ;
27
25
28
26
private IWorkflowHost Host => _serviceProvider . GetService < IWorkflowHost > ( ) ;
29
27
30
- public WorkflowExecutor ( IWorkflowRegistry registry , IServiceProvider serviceProvider , IScopeProvider scopeProvider , IDateTimeProvider datetimeProvider , IExecutionResultProcessor executionResultProcessor , ILifeCycleEventPublisher publisher , ICancellationProcessor cancellationProcessor , WorkflowOptions options , IWorkflowMiddlewareRunner middlewareRunner , IStepExecutor stepExecutor , ILoggerFactory loggerFactory )
28
+ public WorkflowExecutor ( IWorkflowRegistry registry , IServiceProvider serviceProvider , IScopeProvider scopeProvider , IDateTimeProvider datetimeProvider , IExecutionResultProcessor executionResultProcessor , ILifeCycleEventPublisher publisher , ICancellationProcessor cancellationProcessor , WorkflowOptions options , ILoggerFactory loggerFactory )
31
29
{
32
30
_serviceProvider = serviceProvider ;
33
31
_scopeProvider = scopeProvider ;
@@ -38,8 +36,6 @@ public WorkflowExecutor(IWorkflowRegistry registry, IServiceProvider serviceProv
38
36
_options = options ;
39
37
_logger = loggerFactory . CreateLogger < WorkflowExecutor > ( ) ;
40
38
_executionResultProcessor = executionResultProcessor ;
41
- _middlewareRunner = middlewareRunner ;
42
- _stepExecutor = stepExecutor ;
43
39
}
44
40
45
41
public async Task < WorkflowExecutorResult > Execute ( WorkflowInstance workflow , CancellationToken cancellationToken = default )
@@ -157,6 +153,7 @@ private async Task ExecuteStep(WorkflowInstance workflow, WorkflowStep step, Exe
157
153
_logger . LogDebug ( "Starting step {0} on workflow {1}" , step . Name , workflow . Id ) ;
158
154
159
155
IStepBody body = step . ConstructBody ( scope . ServiceProvider ) ;
156
+ var stepExecutor = scope . ServiceProvider . GetRequiredService < IStepExecutor > ( ) ;
160
157
161
158
if ( body == null )
162
159
{
@@ -185,7 +182,7 @@ private async Task ExecuteStep(WorkflowInstance workflow, WorkflowStep step, Exe
185
182
return ;
186
183
}
187
184
188
- var result = await _stepExecutor . ExecuteStep ( context , body ) ;
185
+ var result = await stepExecutor . ExecuteStep ( context , body ) ;
189
186
190
187
if ( result . Proceed )
191
188
{
@@ -250,7 +247,11 @@ private async Task DetermineNextExecutionTime(WorkflowInstance workflow, Workflo
250
247
workflow . Status = WorkflowStatus . Complete ;
251
248
workflow . CompleteTime = _datetimeProvider . UtcNow ;
252
249
253
- await _middlewareRunner . RunPostMiddleware ( workflow , def ) ;
250
+ using ( var scope = _serviceProvider . CreateScope ( ) )
251
+ {
252
+ var middlewareRunner = scope . ServiceProvider . GetRequiredService < IWorkflowMiddlewareRunner > ( ) ;
253
+ await middlewareRunner . RunPostMiddleware ( workflow , def ) ;
254
+ }
254
255
255
256
_publisher . PublishNotification ( new WorkflowCompleted ( )
256
257
{
0 commit comments