@@ -87,57 +87,60 @@ public async Task<WorkflowExecutorResult> Execute(WorkflowInstance workflow)
87
87
pointer . StartTime = _datetimeProvider . Now . ToUniversalTime ( ) ;
88
88
}
89
89
90
- _logger . LogDebug ( "Starting step {0} on workflow {1}" , step . Name , workflow . Id ) ;
90
+ using ( var scope = _serviceProvider . CreateScope ( ) )
91
+ {
92
+ _logger . LogDebug ( "Starting step {0} on workflow {1}" , step . Name , workflow . Id ) ;
91
93
92
- IStepBody body = step . ConstructBody ( _serviceProvider ) ;
94
+ IStepBody body = step . ConstructBody ( scope . ServiceProvider ) ;
93
95
94
- if ( body == null )
95
- {
96
- _logger . LogError ( "Unable to construct step body {0}" , step . BodyType . ToString ( ) ) ;
97
- pointer . SleepUntil = _datetimeProvider . Now . ToUniversalTime ( ) . Add ( _options . ErrorRetryInterval ) ;
98
- wfResult . Errors . Add ( new ExecutionError ( )
96
+ if ( body == null )
99
97
{
100
- WorkflowId = workflow . Id ,
101
- ExecutionPointerId = pointer . Id ,
102
- ErrorTime = _datetimeProvider . Now . ToUniversalTime ( ) ,
103
- Message = String . Format ( "Unable to construct step body {0}" , step . BodyType . ToString ( ) )
104
- } ) ;
105
- continue ;
106
- }
98
+ _logger . LogError ( "Unable to construct step body {0}" , step . BodyType . ToString ( ) ) ;
99
+ pointer . SleepUntil = _datetimeProvider . Now . ToUniversalTime ( ) . Add ( _options . ErrorRetryInterval ) ;
100
+ wfResult . Errors . Add ( new ExecutionError ( )
101
+ {
102
+ WorkflowId = workflow . Id ,
103
+ ExecutionPointerId = pointer . Id ,
104
+ ErrorTime = _datetimeProvider . Now . ToUniversalTime ( ) ,
105
+ Message = String . Format ( "Unable to construct step body {0}" , step . BodyType . ToString ( ) )
106
+ } ) ;
107
+ continue ;
108
+ }
107
109
108
- IStepExecutionContext context = new StepExecutionContext ( )
109
- {
110
- Workflow = workflow ,
111
- Step = step ,
112
- PersistenceData = pointer . PersistenceData ,
113
- ExecutionPointer = pointer ,
114
- Item = pointer . ContextItem
115
- } ;
110
+ IStepExecutionContext context = new StepExecutionContext ( )
111
+ {
112
+ Workflow = workflow ,
113
+ Step = step ,
114
+ PersistenceData = pointer . PersistenceData ,
115
+ ExecutionPointer = pointer ,
116
+ Item = pointer . ContextItem
117
+ } ;
116
118
117
- foreach ( var input in step . Inputs )
118
- input . AssignInput ( workflow . Data , body , context ) ;
119
+ foreach ( var input in step . Inputs )
120
+ input . AssignInput ( workflow . Data , body , context ) ;
119
121
120
122
121
- switch ( step . BeforeExecute ( wfResult , context , pointer , body ) )
122
- {
123
- case ExecutionPipelineDirective . Defer :
124
- continue ;
125
- case ExecutionPipelineDirective . EndWorkflow :
126
- workflow . Status = WorkflowStatus . Complete ;
127
- workflow . CompleteTime = _datetimeProvider . Now . ToUniversalTime ( ) ;
128
- continue ;
129
- }
123
+ switch ( step . BeforeExecute ( wfResult , context , pointer , body ) )
124
+ {
125
+ case ExecutionPipelineDirective . Defer :
126
+ continue ;
127
+ case ExecutionPipelineDirective . EndWorkflow :
128
+ workflow . Status = WorkflowStatus . Complete ;
129
+ workflow . CompleteTime = _datetimeProvider . Now . ToUniversalTime ( ) ;
130
+ continue ;
131
+ }
130
132
131
- var result = await body . RunAsync ( context ) ;
133
+ var result = await body . RunAsync ( context ) ;
132
134
133
- if ( result . Proceed )
134
- {
135
- foreach ( var output in step . Outputs )
136
- output . AssignOutput ( workflow . Data , body , context ) ;
137
- }
135
+ if ( result . Proceed )
136
+ {
137
+ foreach ( var output in step . Outputs )
138
+ output . AssignOutput ( workflow . Data , body , context ) ;
139
+ }
138
140
139
- _executionResultProcessor . ProcessExecutionResult ( workflow , def , pointer , step , result , wfResult ) ;
140
- step . AfterExecute ( wfResult , context , result , pointer ) ;
141
+ _executionResultProcessor . ProcessExecutionResult ( workflow , def , pointer , step , result , wfResult ) ;
142
+ step . AfterExecute ( wfResult , context , result , pointer ) ;
143
+ }
141
144
}
142
145
catch ( Exception ex )
143
146
{
0 commit comments