InsertKoinIO / koin-annotations

Koin Annotations - About Koin - a pragmatic lightweight dependency injection framework for Kotlin & Kotlin Multiplatform insert-koin.io
https://insert-koin.io
Apache License 2.0
123 stars 30 forks source link

Invalid work of KoinViewModel annotation with KMM #86

Open Pschsch opened 1 year ago

Pschsch commented 1 year ago

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:

  1. Declare ViewModel class in commonMain source set
  2. Annotate it with KoinViewModel
  3. Launch compilation for target other, than Android
  4. 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
arnaudgiuliani commented 11 months ago

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.

taetae98coding commented 2 months ago

any update?