Replies: 2 comments
-
I really don't know how you'd go about finding if there's more than one implementation of an interface across a project in an efficient way. |
Beta Was this translation helpful? Give feedback.
0 replies
-
This is the solution to this problem: https://github.com/amzn/kotlin-inject-anvil?tab=readme-ov-file#contributesbinding |
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
-
Currently, using
@Inject
on the implementation of an interface only provides the implementation to the component, but if the interface needs to be resolved we need to write a@Provides
as a kind of alias. In frameworks like Micronaut, the DI knows how to automatically resolve the interface if there's only one implmentation. If there are multiple implementations, if one of them in@Primary
, that one is resolved, and if another class requires all the implementations to be injected it can get them byList<SomeInterface>
and all implementations are injected.For testing, there's a
@Replaces(SomeClass)
annotation to override any primary implementation.See: https://docs.micronaut.io/latest/guide/#replaces
Beta Was this translation helpful? Give feedback.
All reactions