Hi everyone :wave: when using Koin annotations, is...
# koin
o
Hi everyone đź‘‹ when using Koin annotations, is it possible to inject objects across different modules? For example core/ui/.../ProfileEditorViewModel.kt
@KoinViewModel
class ProfileEditorViewModel(
private val userRepository: UserRepository
) : ViewModel()
And in composeApp/.../FakeUserRepo.kt
@Factory
class FakeUserRepo() : UserRepository
Currently I’m using
@Provided
to suppress the injection error and then manually loading
FakeUserRepo
. I also tried
ComponentScan
, but it doesn’t seem to work across modules. What’s the recommended way to handle this?
a
if in one module you have a tagged class, not bound to a particular module, it will be "exported" and available to be scanned by other modules
Else also take a look at
@Configuration
to let you gather modules within same space - https://insert-koin.io/docs/reference/koin-annotations/modules#configuration-management-with-configuration
o
Thanks for your reply! I see that Koin definitions are only visible to scanner within the same Gradle subproject (e.g.,
FakeUserRepo
is in
composeApp
), so
core.ui
subproject scanner doesn’t know about it. Is it possible to inject a tagged class from composeApp/otherApp subprojects (without
@Provided
), and do you have any examples?
a
The @Configuration & @KoinApplication are done for this, helping scanned through modules and gather them
thank you color 1