Replies: 1 comment
-
As of writing this, it does not look like it's possible to severe the dependency between Because the change is conditional, we have to use fx.Decorate(
func(s Store, c *Config) Store {
if c.Development {
return s
}
return NewMemoryStore()
},
) This will still have a dependency on the Redis store. |
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
-
Problem
Suppose a program has a
Store
interface with two implementations: a memory-backed version and a Redis-backed version.The memory store has no dependencies, while the Redis store depends on a Redis client.
The application wants to pick between the two implementations based on a configuration parameter.
Imagine:
However, as a result of this,
NewStore
has a hard transitive dependency on the Redis client, even if the Redis store won't be used.Ideally,
NewStore
should be able to specify which dependency set it wants to use after looking at the configuration.Is this something that is possible today with Fx? Perhaps with
fx.Replace
?Would the dependency on
*redis.Client
be completely disconnected in development with the use offx.Replace
?Beta Was this translation helpful? Give feedback.
All reactions