Closed DaveBoy closed 4 years ago
boxFor return the Box\<T> Koin Version is :2.0.1 // Koin AndroidX Scope features implementation "org.koin:koin-androidx-scope:$koin_version" // Koin AndroidX ViewModel features implementation "org.koin:koin-androidx-viewmodel:$koin_version" // Koin AndroidX Fragment features //implementation "org.koin:koin-androidx-fragment:$koin_version" // Koin AndroidX Experimental features implementation "org.koin:koin-androidx-ext:$koin_version"
The problem is that Koin works in runtime and has no information about generics. You can find in the documentation
The problem is that Koin works in runtime and has no information about generics. You can find in the documentation
i am not found this doc before,but this solution of the doc is same as my second try(add named),and it happen the error:
Caused by: org.koin.core.error.NoBeanDefFoundException: No definition found for 'io.objectbox.Box' has been found. Check your module definitions.
at org.koin.core.scope.Scope.findDefinition(Scope.kt:170)
at org.koin.core.scope.Scope.resolveInstance(Scope.kt:164)
at org.koin.core.scope.Scope.get(Scope.kt:128)
at com.example.myapplication.MainActivity$$special$$inlined$inject$1.invoke(ComponentCallbackExt.kt:51)
at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
at com.example.myapplication.MainActivity.getSongBox(MainActivity.kt)
at com.example.myapplication.MainActivity.initObjectBox(MainActivity.kt:31)
at com.example.myapplication.MainActivity.onCreate(MainActivity.kt:18)
at android.app.Activity.performCreate(Activity.java:6910)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2746)
The problem is that Koin works in runtime and has no information about generics. You can find in the documentation
i use it like this in MainActivity
//use
val songBox:Box<Song> by inject()
You need to use the same qualifier in declaration and injection:
val objectModel= module {
single (named("song")){ ObjectBoxUtil.boxStore.boxFor<Song>() }
single (named("album")){ ObjectBoxUtil.boxStore.boxFor<Album>() }
}
val songBox:Box<Song> by inject(qualifier = named("song"))
val songBox:Box<Album> by inject(qualifier = named("album"))
i want to di double object like this:
when i add one of them,it's ok but when i add the second one:
i change it to this:
it become this error:
the other code
what's the correct action? please help me.thanks