danielgerlag / danielgerlag/workflow-core
IWorkflowMiddlewareErrorHandler never invoked
- Dominant language
- C#
- Stars
- 5.9k
- Forks
- 1.3k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 5
Description
Hi all,
I have an ASP.NET Core 6 Web API project and registering the services in Startup.cs like below.
```
public void ConfigureServices(IServiceCollection services)
{
services.AddWorkflow();
services.AddTransient();
services.AddTransient();
services.AddTransient();
services.AddTransient();
services.AddTransient();
}
```
There are plenty of other dependencies registered of course. Below I am starting the workflow in the `Configure` method.
```
public void Configure(IWorkflowHost workflowHost, IHostApplicationLifetime hostApplicationLifetime)
{
hostApplicationLifetime.ApplicationStopping.Register(workflowHost.Stop);
workflowHost.RegisterWorkflow();
workflowHost.Start();
}
```
What I want to accomplish is any step throwing an exception to let it bubble up to the stack and be handled by ASP.NET Core (or in my case from a middleware in ASP.NET Core).
Here's my `IWorkflowMiddlewareErrorHandler` implementation.
```
public class WorkflowMiddlewareErrorHandler : IWorkflowMiddlewareErrorHandler
{
public Task HandleAsync(Exception ex)
{
throw ex; // this line of code never invoked.
}
}
```
Here's my workflow.
```
public class CitizenAdminDeleteAccountWorkflow : IWorkflow
{
public string Id => nameof(CitizenAdminDeleteAccountWorkflow);
public int Version => 1;
public void Build(IWorkflowBuilder builder)
{
builder
.Saga(saga => saga
.StartWith()
.Input((step, data) => step.Data = data)
.CompensateWith(compensate =>
compensate.Input((step, data) => step.Data = data))
.Then()
.Input((step, data) => step.Data = data)
)
.OnError(WorkflowErrorHandling.Terminate);
}
}
```
And a sample step.
```
public class DoInfluencerDeleteAccountStep : StepBodyAsync
{
public override async Task RunAsync(IStepExecutionContext context)
{
throw new DomainException("blah");
return ExecutionResult.Next();
}
}
```
Calling the workflow.
```
private readonly ISyncWorkflowRunner _runner;
var workflowInstance = await _runner.RunWorkflowSync(
nameof(CitizenAdminDeleteAccountWorkflow),
1,
new CitizenAdminDeleteAccountWorkflowData
{
Command = command,
CancellationToken = cancellationToken,
AppSettings = _appSettings
},
nameof(DeleteCitizenAdminAccountCommandHandler),
cancellationToken);
```
Any idea why the middleware isn't registered so that it will be invoked in any step exception and just let the program fail?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.