Mixed lifetime of injected dependencies #2200
Unanswered
adomaskizogian
asked this question in
Q&A
Replies: 1 comment
-
Hey @adomaskizogian I'm also running into the same thing - did you ever work around this? |
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
-
Hey,
So as far as I know, the
resolvers.go
is the place where you manually define the resolvers, their dependencies and wire everything up. Using package scoped variables,sync.once
and pass every dep as a reference one can achieve the singleton lifetime of dependencies.I am dealing with a case where some of the dependencies should be scoped to the lifetime of a http request/response. This could be for instance request scoped dataloaders, request scoped http clients that rely on some request headers (be it
X-Fowarder-For
address, some auth headers, etc). In the ideal scenario, these dependencies (e.g. customRoundTripper
,HttpClient
implementations that can be shared) would be scoped to the http request/response lifetime and the rest would be global singletons.I was wondering if any of you have dealt with that already and could share your tips, suggestion on how to achieve this optimized dependency injection without bloating and abusing the
context.Context
or at least how to limit the
contex.Context
usage as it is quite clear that if I don't want to recreate the whole dependency graph, I have to rely on function argument based injection not on struct creation time injectionThanks!
Beta Was this translation helpful? Give feedback.
All reactions