<Doc> says optional dependency to be injected like...
# koin
l
Doc says optional dependency to be injected like this
Copy code
import org.koin.java.KoinJavaComponent.injectOrNull

val crashReporter: CrashReporter? by koin.injectOrNull()
howevert method signature is
Copy code
fun T injectOrNull(
        clazz: Class*,
        qualifier: Qualifier? = null,
        parameters: ParametersDefinition? = null,
    ): LazyT?
so to use you must pass type twice no?
Copy code
val titi = injectOrNullTiti?(Titi::class.java)
👀 1
e
There is
Copy code
inline fun <reified T : Any> injectOrNull(
        qualifier: Qualifier? = null,
        mode: LazyThreadSafetyMode = KoinPlatformTools.defaultLazyMode(),
        noinline parameters: ParametersDefinition? = null,
    ): Lazy<T?>
l
I can't find it in 4.2.2, could you share your import 🙏
e
Copy code
org.koin.core
🙏 1
l
That's funny actually that is defined in
org.koin.core.Koin
but class is
@OptIn(KoinInternalApi::class)
so I think it is not meant to be used
e
You're right
If it is internal - not intended to be used
l
@arnaud.giuliani is the doc to update or the API to evolve 🙏
a
It's public - must be doc mismatch then
l
sorry maybe I am just misusing it, I said that because it is to be found inside
Copy code
@OptIn(KoinInternalApi::class)
class Koin {
what import or context should I have to make it work? intellij imports for me
Copy code
org.koin.java.KoinJavaComponent.injectOrNull
which expects the class as param
a
KoinJavaComponent
?
injectOrNull is from
Koin
instance
this is perhaps not exposed in
KoinJavaComponent
👍 1