We have, probably, a similar challenge. Our SDK us...
# koin
j
We have, probably, a similar challenge. Our SDK uses Koin, internally. Consuming apps may or may not use Koin (if they don't, they'll bridge Koin's dependencies into Hilt). The SDK has different features that not all apps need. For every feature, we have a
FeatureEntryPoint
with an
init()
method that does
koin.loadModules(SomeFeatureModule().module)
, where
koin
is the SDK's internal Koin instance. How to achieve this with the compiler plugin?
.module
doesn't exist anymore. The docs state doing everything in
startKoin
, but we don't know what configuration the consuming app needs. All DI config is internal to the SDK.
👀 1
r
j
Ehhh, that compiles! Both in Kilua and our project, but that
module()
method is never known to the IDE 😅
r
There is probably a better solution now available, but haven't checked that yet: https://kotlinlang.slack.com/archives/C67HDJZ2N/p1774246233813049
j
I only call this from sub classes of our
FeatureEntryPoint
, so I tried adding this placeholder:
Copy code
/**
 * Placeholder for the `module()` method that Koin's compiler plugin generates, so the IDE
 * knows about it.
 */
protected fun Any.module(): Module {
    error("This will should have been overwritten by Koin compiler")
}
IDE is happy but runtime is not, unfortunately. (We're on koin
4.2.1
and koin-plugin
1.0.0-RC1
)
@arnaud.giuliani any suggestion for this? (Still relevant with RC2)
a
let me check the API 👍 perhaps missing for side loading from Koin directly
you should yes reified type
j
@arnaud.giuliani (or @Robert Jaros) any idea on how to get the IDE to see this
module()
method call?
But I think I have changed my code a bit.
Instead of passing a module as a parameter I now execute a module() extension function on KoinApplication receiver.
j
Yeah, I see. May have to rethink my setup. Thanks!
r
I remember now. I was using the extension on the receiver earlier as well. But I was using
KoinApplication.modules(Module1.module(), Module2,module())
and this was not correct in IDE. Then I tried using
KoinApplication.modules(Module1::class, Module2::class)
but it doesn't work. So I tried
KoinApplication.module<Module1>()
and it works ok, I just need multiple calls for each module.