Koin how to inject outside of Android activity / appcompatactivity

There is the KoinComponent which comes to the rescue. In any class you can simply:

class SampleClass : KoinComponent {

    val a : A? by inject()
    val b : B? by inject()
}

Extending KoinComponent gives you access to inject() method.

Remember that usually it’s enough to inject stuff the usual way:

class SampleClass(val a : A?, val b: B?)

Leave a Comment

tech