Multiplatform/Native/Koin question: I'm not sure w...
# koin
p
Multiplatform/Native/Koin question: I'm not sure what the "correct" way is to utilize Koin when I need to provide an implementation in iOS in swift. There are some 3rd party libs that are in swift that I would like to inject into the Koin modules, which are all defined in the common shared code.
e.g., I have an interface
CommonIF.kt
defined in commonMain/interfaces, and a
CommonImpl.kt
in androidMain. In iOS, this is implemented in swift by implementing the
CommonIF
interface. Now the question is how I can make this available to Koin when calling
startKoin
on in my iosMain code. I have an
ModuleLoader
that starts koin and loads the module. The naive approach that I've been using for testing is to add a constructor parameter to
ModuleLoader(val commonImpl: CommonIF)
and provide that in the module by returning this item:
Copy code
single<CommonIF> { commonImpl }
This breaks the purpose of DI and makes the interface fairly messy and also requires eager loading of these native implementations. Is there a way to clean this up so that the iOS instance is lazily loaded? Is there a way to define Koin modules in swift so that I could just pass in iOS specific Koin modules to the
ModuleLoader
?