-
Notifications
You must be signed in to change notification settings - Fork 290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple implementations #1096
Labels
Comments
The easiest way to achieve this is by using a flag that can be obtained through configuration or a command-line argument. fx.New(
fx.Provide(
func() string {
var country string
// parse config
return country
},
),
fx.Provide(
func(country string) CountryInterface {
switch country {
case "us":
return NewUS()
case "uk":
return NewUK()
default:
return NewDefault()
}
},
),
) It is also recommended not to use plain strings for representing the country value in fx. Instead, it's better to use a separate custom type or use name tag |
That's right, but it is not we want to do. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi ! Awesome project ! I love it 🥵.
Do you know how to implement something similar to profiles in Spring Boot, but with FX?
The concept of profiles allows having multiple implementations of the same interface, but at runtime, only one dependency is available based on a configuration parameter. For example, implementing different versions based on country.
Could you please explain how to achieve this?
Thanks a lot !!
The text was updated successfully, but these errors were encountered: