Lilly
06/01/2024, 12:22 AMval appModule = module {
singleOf(::MovieRepository)
singleOf(::UpdateMovieUseCase) { bind<UseCase<List<MovieDomainModel>>>() }
singleOf(::EditMovieUseCase) { bind<UseCase<EditMovieDomainModel>>() }
}
// This does not work
val updateUseCase = koinInject<UseCase<List<MovieDomainModel>>>()
// This works
//val updateUseCase = koinInject<UpdateMovieUseCase>()
val editUseCase = koinInject<UseCase<EditMovieDomainModel>>()
println(updateUseCase)
println(editUseCase)
Both will print com.example.composetest.EditMovieUseCase@554e934
Can I achieve this with named qualifier?
Issue: https://github.com/InsertKoinIO/koin/issues/1883arnaud.giuliani
06/04/2024, 2:04 PMLilly
06/04/2024, 8:59 PMval appModule = module {
single(named("Lol")) { UpdateMovieUseCase(get()) } withOptions {
bind<UseCase<List<MovieDomainModel>>>()
}
single { MovieWrapper1(get(named("Lol"))) }
single { MovieWrapper2(get(named("Lol"))) }
}
class MovieWrapper1(private val movieUseCase: UseCase<List<MovieDomainModel>>) {}
class MovieWrapper2(private val movieUseCase: UseCase<List<MovieDomainModel>>) {}
When I inject MovieWrapper1
and MovieWrapper2
it creates two different instances instead of referencing the same. How can I achieve this?arnaud.giuliani
06/05/2024, 12:47 PMit creates two different instances instead of referencing the sameyes your code is written like that
arnaud.giuliani
06/05/2024, 12:48 PMarnaud.giuliani
06/05/2024, 12:48 PMUpdateMovieUseCaseshould be injected in both MovieWrapper1 MovieWrapper2?
arnaud.giuliani
06/05/2024, 12:49 PMLilly
06/07/2024, 10:09 AM