Peter Hsu
02/12/2022, 9:45 PMPeter Hsu
02/12/2022, 9:53 PMCommonIF.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:
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
?