C# - No DI - so how to pass IOptions into WF?

I have a workflow and I want to use IOptions from C# which a common practice to do in your services. However, it’s advised not to do that. How does one propose passing IOptions into Workflow? I could get them in program.cs and pass them in as part of run, but that seems like not an ideal way to do that. Create a static variable for the options and access them that way? Looking for the best way to do this. Thanks for the help.

Since workflows need to be deterministic, you usually would not have something specific to a certain machine. The common way to do this is to either pass this information in via workflow input (e.g. add a serializable field on your existing workflow parameter record ) or create a local activity that returns a serializable form of this information back to the workflow. Both ways will make sure your workflow has this options/config in history and not subject to mutations/differences later or on different machines.

If just the activities need this DI’d data, no need for it to flow through the workflow, activities support DI (see here). But if workflows need it, can’t DI (it’s unsafe), have to use one of the two approaches mentioned above.

(pasted answer from Slack, did not see this question in forums first, just added dotnet-sdk tag)

1 Like