How to smartly invoke methods of different types? #1041
Unanswered
aksgupta98
asked this question in
Q&A
Replies: 1 comment
-
You may want to check out our docs. First, Invoke shouldn't be used for doing things like this - see: https://uber-go.github.io/fx/modules.html#invoke-sparingly. For the purpose of initializing a variable that was provided to the DI container, you can use [fx.Populate]https://pkg.go.dev/go.uber.org/fx#Populate) to extract the value. That being said, the whole point of Fx is to avoid having to initialize your "global variables" this way. You may benefit from using Lifecycles for managing the lifecycles of your components: https://uber-go.github.io/fx/lifecycle.html |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi everyone, I am building a go application which has multiple modules. Each module has a different service hence I do not want to clutter my code by invoking every service before using it.
Please suggest a better way to achieve this
My Current Code looks like this -
I have used Invoke multiple times to get a instance of a service, and I am sure there is a better way to do it.
Beta Was this translation helpful? Give feedback.
All reactions