Questions tagged [koin]

Koin is a Dependency Injection framework for Kotlin developers.

Koin is a pragmatic lightweight open-source dependency injection framework for Kotlin developers.

Links:

482 questions
7
votes
2 answers

How to inject viewModel in BaseFragment using Koin

I have created an abstract BaseFragment class which will be extended by other concrete Fragment classes. I want to inject ViewModel in my BaseFragment using Koin. Here is my BaseFragment: abstract class BaseFragment
sagar suri
  • 4,351
  • 12
  • 59
  • 122
7
votes
1 answer

koin pass CoroutineScope as dependency for RoomDatabaseCallback

I have a database which requires a CoroutineScope for initialization. @Database(entities = [Word::class], version = 1) abstract class WordRoomDatabase : RoomDatabase() { abstract fun wordDao(): WordDao companion object { @Volatile private var…
Nurseyit Tursunkulov
  • 8,012
  • 12
  • 44
  • 78
7
votes
3 answers

How to retrieve all instances that matches a given type using Koin Dependency Injection (Kotlin)

How do you achieve the following using Koin DI: single { AValidator() } bind IValidator::class single { BValidator() } bind IValidator::class single { CValidator() } bind IValidator::class single { DValidator() } bind IValidator::class In the class…
M Ahayan
  • 121
  • 1
  • 5
7
votes
1 answer

Facing issues with adding sharedPreferences and the sharedPrefrencesEditor to Koin module

I recently got to know about Koin. I was trying to migrate my current project from Dagger to Koin. In doing so, I faced an issue with injecting sharedPreferences and sharedPreferences editor in the activities. Following is the code I used in Dagger…
Annsh Singh
  • 435
  • 5
  • 12
7
votes
3 answers

Can I manage lifecycle owner, injecting viewModel with Koin?

I have single Activity application. I want to bind viewModel to the parent fragment lifecycle (FlowFragmentLogin), and share it with child fragments (CellFragment, InfoFragment, etc). So that when I move from FlowFragmentLogin to FlowFragmentMain,…
6
votes
1 answer

How to provide ViewModel that has interface via Koin

I have the following ViewModel setup: interface FooViewModel {} class FooViewModelImpl: ViewModel(), FooViewModel {} and I want to provide it via Koin like this: viewModel { FooViewModelImpl() } It doesn't work because Koin expects…
Nijat Ahmadli
  • 711
  • 6
  • 13
6
votes
1 answer

Is Dynamic Dependency Injection with Koin possible

I am investigating Koin dependency injection library in my current Android application. I have a CoroutineWorker that completes all my background work. What I would like to do is Dynamically inject a lambda for each type of background work I have. I…
Hector
  • 4,016
  • 21
  • 112
  • 211
6
votes
0 answers

Koin analogue to Dagger IntoSet

Does Koin provide the functionality of binding several dependencies into a collection, as Dagger does with multibindings? Let's suppose I have this interface: interface Initializer: (Application) -> Unit And this interface has several…
Stanislav Shamilov
  • 1,746
  • 11
  • 20
6
votes
2 answers

How to provide the base class in Koin?

For example I the following classes: abstract class BaseClass() class SpecificClass : BaseClass() Now, I want to provide SpecificClass through koin dependency inject but I also want to provide the base class BaseClass in the same graph. To be…
Archie G. Quiñones
  • 11,638
  • 18
  • 65
  • 107
6
votes
2 answers

Unresolved reference:test in KoinTest

I'm trying to do some test with Koin, but I'm getting the "Unresolved reference:KoinTest' howeber, seems that is doing the imports correctly, because I can't see any error in the code. Is only when I try to run the test. I've tried to clean and…
S.P.
  • 2,274
  • 4
  • 26
  • 57
6
votes
1 answer

Kotlin Lazy loading not working in Junit test

Hi i am trying to load/inject variables into my unit test using kotlin koin and it fails to do so and i get a no class def found error when i try to use the variables. Below is my module: val testModules = module { …
Jono
  • 17,341
  • 48
  • 135
  • 217
6
votes
2 answers

Koin Scope and Interface

I am using Koin di library in my project. Version of lib is 1.0.0-RC-1. My module: val appModule = module { scope("UserScope") { UserToaster(androidContext()) as Toaster } scope("AnonScope") { AnonToaster(androidContext()) as Toaster } } I…
KolinLoures
  • 130
  • 2
  • 10
5
votes
1 answer

I have a problem when i am testing ktor. Basically the ApplicationTest class is not injecting repository class it show an error of java..ClassCastExce

This is my application test class class ApplicationTest { private val heroRepository: HeroRepository by inject(HeroRepository::class.java) @OptIn(InternalAPI::class) @Test fun `access all heroes endpoints, assert correct…
5
votes
3 answers

how can i fix the installation of Koin in ktor/intellij

I'm trying to use install koin but it gives the following text when i hover over it. Type mismatch. Required: Plugin Found: Koin.Feature the code is as in the following: import…
5
votes
0 answers

inject workmanager through koin Android

Hey I am using Koin in my application. I am trying to inject workmanager in my application according to this answer. I did this successfully but I have little bit confused about workManagerFactory() Module.kt val workerModule = module { //…
Kotlin Learner
  • 3,995
  • 6
  • 47
  • 127