Reputation: 28
The same class can rely on injection if it USES get() or by inject() in an activity, but if it is not used in an activity, it will report an error when injecting. Why?
error:
Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: public inline fun ComponentCallbacks.get(qualifier: Qualifier? = ..., noinline parameters: ParametersDefinition? /* = (() -> DefinitionParameters)? */ = ...): xxClass defined in org.koin.android.ext.android
Upvotes: 0
Views: 542
Reputation: 959
In order to be able to inject koin objects in your classes, you need to implement the KoinComponent interface (see documentation here)
The reason you could use by inject()
or get()
in Activities and Fragments directly without implementing KoinComponent is because Koin does that automatically for you! It leverages the power of extension functions so that they are considered a KoinComponent.
Upvotes: 0