:wave: In the following configuration : Module A h...
# koin
h
👋 In the following configuration : Module A has a
UseCase
annotated with
@Single
, Module B has a ViewModel annotated with
@KoinViewModel
injecting
UseCase
and Module DI adds A and B and
startKoin
Is it possible to isolate Koin Configuration (ksp application) in the module DI and then have something like this :
Copy code
@Module
@ComponentScan("moduleA.package")
class ModuleA

@Module
@ComponentScan("moduleB.package")
class ModuleB

startKoin {
    modules(ModuleA().module, ModuleB().module)
}
Edit: I was reading this article but I didn't manage to make it work
a
isolate Koin Configuration
Like with IsolatedContext ?
h
No 😄 I was just wondering if the gradle configuration can be isolated (i.e only apply ksp logic on DI module)
The documentation says : > When using
@ComponentScan
annotation, KSP traverses accross all Gradle modules for the same package. (since 1.4) But the generated Koin Module stays empty
Copy code
public val template_di_ModuleA : Module get() = module {
}
Gradle Module DI (KMP) :
Copy code
// in build.gradle.kts
apply(ksp)
implementation(ModuleA)
implementation(ModuleB)
// [...] Other Koin annotation configuration..

// Expose a KoiHelper object to startKoin
object KoinHelper {
    fun init(block: KoinApplication.() -> Unit) {
        startKoin {
            modules(ModuleA().module)
            block()
        }
    }
}

// Create a Module
@Module
@ComponentScan("moduleA.package")
class ModuleA
Gradle Module A :
Copy code
package moduleA.package
@Single MyUseCase { }
I think I'm missing something
a
it stays empty due to package name? even with one module?