Go-SDK Dependency Injection


I’m quite new to the temporal and I’m struggling to see how I should be injecting my database pool connection into my activities. I suspect that I’m simply overthinking this. I’m using this sample as reference.

I see that the activities are registered using a struct. Ideally, I would like to register my activities using a struct that holds an interface reference to my database layer. Then when registering the activity on the worker, I can pass the struct with the concrete struct. Is this the correct/a valid approach?

Yes, the same way the greeetings sample passes Name and Greeting to the struct you can pass any external dependencies like DB pools.

1 Like