Dependency injection (e.g. DB connection) for activity worker in Go


There are parameters of executing my workflow and its activities that have more to do with the environment in which it runs than the parameters of the workflow.

How can I have these dependencies be initialized as part of the worker, and made available to workflows and activities?

Thank you for your help,


Activities can be implemented as Go structures. As an instance of a structure is registered with a worker it is possible to assign whatever dependencies to the structure fields during its initialization.

Workflows are always functions and it is not advised to pass any parameters to them directly as it might break workflow code determinism if these parameters change in the middle of workflow execution. So the recommended way is to have an activity that returns the parameters. This way they end up recorded in the event history and cannot affect workflow determinism even when changed.

Here is an example of activity structure initialization.


This is exactly what I was looking for. Thank you Maxim. :smile: