koin-annotations
koin-annotations copied to clipboard
Invalid work of KoinViewModel annotation with KMM
Describe the bug Koin Annotations use org.koin.androidx.viewmodel package for all platforms to generate viewModel definition
To Reproduce Steps to reproduce the behavior:
- Declare ViewModel class in commonMain source set
- Annotate it with KoinViewModel
- Launch compilation for target other, than Android
- See compilation error
Expected behavior It's a little difficult to say, what declaration should be in jvm, ios and other platforms. Maybe single? UPD: Exactly, factory
Koin project used and used version (please complete the following information):
[e.g]: koin-annotations version 1.2.2
Additional moduleDefinition
import org.koin.core.module.Module
import org.koin.dsl.*
import org.koin.androidx.viewmodel.dsl.viewModel /*error*/
/*Pure JVM platform declaration*/
public val ru_example_mortgage_MortgageModule : Module = module {
single() { ru.example.mortgage.businesslogic.MortgageServiceImpl() } bind(ru.example.mortgage.businesslogic.MortgageService::class)
viewModel() { ru.example.mortgage.MortgageViewModel(get(),get(),get()) }
}
public val ru.example.mortgage.MortgageModule.module : org.koin.core.module.Module get() = ru_example_mortgage_MortgageModule
The @KoinViewModel
annotation target the Android platform for now. This is why the annotation is in package org.koin.android.annotation
. But then I agree, nothing prevents from using it in KMP project in common part for example.
any update?
I guess https://github.com/InsertKoinIO/koin-annotations/pull/138 should have fixed this but it does not help. It still imports org.koin.androidx.viewmodel.dsl.viewModel vs org.koin.compose.viewmodel.dsl.viewModel
我猜#138应该已经修复了这个问题,但它没有帮助。它仍然导入 org.koin.androidx.viewmodel.dsl.viewModel 而不是 org.koin.compose.viewmodel.dsl.viewModel
Yes, No matter where I add ksp { arg("KOIN_USE_COMPOSE_VIEWMODEL", "true") }, it doesn't work!