Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to resolve a custom step name when I use a generic workflow step type? #1337

Open
cervengoc opened this issue Feb 17, 2025 · 1 comment

Comments

@cervengoc
Copy link

cervengoc commented Feb 17, 2025

I've implemented my workflow steps as the following.
I have a generic workflow step type, like this:

public class GenericWorkflowStep<THandler, TInput, TOutput> : StepBodyAsync
{
   ...
}

Each of my actual step handlers look something like this:

public class MyStepHandler
{
    public async Task<MyStepOutput> Execute(MyStepInput input, CancellationToken ct)
    {
        ...
    }
}

In the generic workflow step I dynamically resolve a handler instance, and call its Execute method by convention, etc.
The point with this design is to have loosly coupled handlers for our workflows, which by themselves do not depend on WFC in any manner.

However, at the moment WFC resolves the name of a step using the type name, so every step will become "GenericWorkflowStep``1", which definitely cause some UI and listing related issues on our side, but may cause some unwanted effects on WFC side as well.

I'm aware that I can pass an explicit step name when building the workflows. However, we have many workflows, using many shared steps, so that would be a huge and error-prone work (eg. what if a developer misses it somewhere).

What is the best way to implement some kind of centralized logic to resolve the step name in a custom way, for example in this case using the third generic type argument of the step type?

@cervengoc
Copy link
Author

cervengoc commented Feb 17, 2025

In addition, I started to "play" with inheriting from WorkflowBuilder and WorkflowBuilder<TData>, and override the Build method so that for each step which has this generic type, the step names are "fixed" from step.BodyType.

However, I struggle to get it work, as the UseData<TData> method of the non-generic WorkflowBuilder is not virtual, hence always instantiating the default WorkflowBuilder<TData> type.

Of course there would probably be the obvious chance to decorate the IWorkflowBuilder and IWorkflowBuilder<T> interfaces with this extended implementation, however, that does not seem to be very clean as two dozens of methods must be implemented/redirected to the wrapped instance.

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

No branches or pull requests

1 participant