gps
11/16/2020, 7:23 AMKoinComponent
interface, and then using inject
. I don't need to do this if I'm using it in the context of a route, or application, but I think I do need to do this if I'm using it my own classes? After upgrading to Koin 2.2.0 however, I'm getting a warning asking me to add an annotation: KoinApiExtension
. This suggests to me that I'm likely doing something stupid here. Why is it a bad idea for me to implement KoinComponent
? Thanks!arnaud.giuliani
11/16/2020, 8:34 AMKoinComponent
is to help you extend Koin API where there is not already extension for your classesarnaud.giuliani
11/16/2020, 8:35 AMgps
11/16/2020, 11:10 AMKoinComponent
may indeed be the right thing to do?gps
11/16/2020, 11:10 AMgps
11/16/2020, 11:10 AMimport com.typesafe.config.Config
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
class Foo : KoinComponent {
private val config by inject<Config>()
fun doSomething() {
val foo = config.getString("foo")
println(foo)
}
}
gps
11/16/2020, 11:10 AMinject
from Foo
?gps
11/16/2020, 11:12 AMFoo
with @KoinApiExtension
, which in turn requires an OptIn
at all use-sites of Foo
. is this the “expected” outcome? i ask because i’m not sure I fully understand why this warning is a good idea (i’m not saying it’s not a good idea - just want to understand why)arnaud.giuliani
11/16/2020, 12:27 PMOptIn
is the way to go to assume your usage of KoinComponentarnaud.giuliani
11/16/2020, 12:27 PMianbrandt
11/25/2020, 6:21 AMKoinComponent
as the gateway API for the container, and neither makes any mention of @KoinApiExtension
. Why is it desirable to have to opt in to this API? Is there some other API we should be using instead from 2.2.0 on to achieve the same thing as the `HelloApp`/`MyComponent` examples?
One thing I noticed that seems not desirable is since the retention is AnnotationRetention.BINARY
it exposes Koin as an API dependency instead of just an internal implementation dependency.arnaud.giuliani
11/25/2020, 1:27 PMKoinComponent
is a way to bootstrap Koin where we don’t already have any extensions.arnaud.giuliani
11/25/2020, 1:28 PMianbrandt
11/25/2020, 4:38 PMKoinComponent
implementation internal:
@OptIn(KoinApiExtension::class)
internal class HelloApp : KoinComponent {
With @OptIn
being experimental, I had to opt-in to it itself in my build:
kotlinOptions.freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
gps
11/26/2020, 5:05 AMKoinComponent
frivolously, especially when there are extensions already available for “standard” use sites, for the codebase I’m working on, it looks like implementing KoinComponent
really is the best option.