koin-annotations
koin-annotations copied to clipboard
Unable to provide the Dependecy via constructor of module or component,
Describe the bug Unable to provide the Dependecy via constructor of module or component,
I need to provide the ApplicationEnvironment, so it can be consumed in this as well as other module
@Module class AppModule constructor(private val applicationEnvironment: ApplicationEnvironment) { @Factory fun provideApplicationConfig(): ApplicationConfig = applicationEnvironment.config }
@Module(includes = [AppModule::class]) @ComponentScan("dev.reprator") class AppComponent(private val applicationEnvironment: ApplicationEnvironment)
I am getting error as follows:
e: file:///Users/vikram/AccountBook_Backend/build/generated/ksp/main/kotlin/org/koin/ksp/generated/AppModuleGendev$reprator$di.kt:8:48 No value passed for parameter 'applicationEnvironment' e: file:///vikram/AccountBook_Backend/build/generated/ksp/main/kotlin/org/koin/ksp/generated/AppNetworkModuleGendev$reprator$di.kt:8:36 No value passed for parameter 'applicationEnvironment'
Expected behavior there should be some method or something to provide the dependency from top level
Koin project used and used version (please complete the following information):
[e.g]: koin-core version 3.5.3
Repository: https://github.com/TheReprator/AccountBook_Backend/tree/koinAnnotation Branch: koinAnnotation
File where issue can be find easily: Just run this test(https://github.com/TheReprator/AccountBook_Backend/blob/koinAnnotation/src/test/kotlin/dev/reprator/ApplicationInvalidRoutingTest.kt)
or build the project("./gradlew build")
Regards, Vikram Singh
Ok I see, you would like an injection at class module level
This is the same issue I encountered working with Ktor, described in #95. Initially I also wanted a way to provide constructor injection for a module, but that wouldn't work with the @Module(includes=[ModuleWithConstructor::class]) as the annotation cannot know if it should look for non-zero-arg constructors, or even then, with what to call them.
My concern with the code sample you provided is that you suggest that when importing a module with a constructor, the constructor of the parent module should also contain the dependencies so they can be resolved and address the includes problem, but I worry that if you want to have many imports per module (or even worse, have them nested) then the argument list would become very messy.
can write a pseudo code example?