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
3
votes
1 answer

Dependency Injection with Koin in iOS (KMM)

I'm using Koin in a KMM project. On Android it's working as expected but on iOS I have to create a wrapper around each component I want to inject, something like this (Logger component as an example): inline fun getKoinInstance() = …
Emanuel Moecklin
  • 28,488
  • 11
  • 69
  • 85
3
votes
2 answers

init { } block in Android ViewModel is repeatedly called and collects flow when app is brought to the foreground

In my Android app, with Kotlin and using Koin dependency injection, my init block is repeatedly called every time the app is brought into the foreground. The issue this causes is making additional background calls that are not necessary when the app…
3
votes
2 answers

Koin: how to reduce the visibility of modules (private non-exported modules)

I'm using Koin 3.2 which has the new module includes feature. In the official docs, when discussing module linking strategies, there is this paragraph: An important detail to observe is that you can use includes to add internal and private modules…
Mister Smith
  • 27,417
  • 21
  • 110
  • 193
3
votes
1 answer

Why is Koin scoping feature not working properly?

So scoping with Koin DI seem to throw a weird exception when KoinApplication::checkModules() method is called within a unit test. Here is the full code: import org.koin.core.KoinApplication import org.koin.core.component.KoinComponent import…
3
votes
0 answers

SavedStateHandle doesn't contain navigation arguments

I'm trying to inject SavedStateHandle. I am using Koin, Jetpack Compose and Navigation. I've managed to make it work, but I think it's not the right instance (I don't get my values). This is what I do so far: Setting the argument: private fun…
grrigore
  • 1,050
  • 1
  • 21
  • 39
3
votes
0 answers

Koin singleton injection vs Kotlin object

I'm a bit confused should I use Koin or any other dependency Injection for providing repositories to ViewModel or Should I use Kotlin object class for repositories so that we don't need to pass any dependency to ViewModel. Also for unit testing, we…
Sachin Gurnani
  • 2,444
  • 7
  • 36
  • 45
3
votes
3 answers

How to share HttpClient between Multiplatform Ktor and Coil?

I want to use Coil image library to load images from the api with the same cookie that was set before. Therefore I want to use the same HttpClient both for my Ktor networking calls and for Image Loading with Coil. How can I share the same HttpClient…
3
votes
2 answers

Mysterious Signal 11 crash when accessing Room database

About I have an android application, which has 2 activities. Activity A spawns Activity B, and Activity B accesses Room Database in another module. I'm using Koin for all dependency injections, and rxandroid (Schedulers.io() for observing and UI…
Olli
  • 375
  • 5
  • 15
3
votes
2 answers

startKoin crash, library

Recently I published a library with koin; when I used this library in my own application, everything is ok because I don't use Koin in my application, but if I startKoin in my application and the library both, the app crashes!. Is there any way to…
hamid Mahmoodi
  • 690
  • 4
  • 16
3
votes
1 answer

How to test my viewModel that is Koin injected?

I have a ViewModel. It calls a funtion in my data repo and gets back a list of the dog object. class MainViewModel() : ViewModel() { private val dataRepo: DataRepo by inject(DataRepo::class.java) //dataRepo private var limit = 10 private…
Kush Singh
  • 157
  • 3
  • 11
3
votes
0 answers

Koin - Ensure that all "by inject" are valid

I work on an Android project using multiple Project Flavors, and we use Koin to inject the appropriate dependencies based on the current flavor. We already use the checkModules Gradle task (described here :…
Adrien Dos Reis
  • 472
  • 2
  • 14
3
votes
0 answers

Mock method to throw PersistenceException and StatusPages receives a different exception

I was trying to make a unit test that verifies that an exception thrown by hibernate would be handled and would result in a proper response. The exception is a PersistenceException() with cause being a ConstraintViolationException(). So I handled it…
3
votes
2 answers

Koin DI Android Unit testing ViewModel

I use Koin DI in my app, and everything works fine. I have injected viewModels without no issue. Eg, I have a calcViewModel with function: class CalcViewModel(): ViewModel() { fun calculateNumber(): Int{ var a = 5 + 3 return a …
Adrian Ivasku
  • 1,118
  • 3
  • 16
  • 31
3
votes
1 answer

How to dynamically change a dependency?

I have an interface named CrmRepository from which I implemented two classes SuiteCrmRepository and OneCrmRepository which are data sources for my application. I want to swap the dependency (data source) dynamically whenever the user login with a…
George O
  • 139
  • 1
  • 11
3
votes
1 answer

How to inject Room in viewmodel using koin

This is my first mvvm project with koin and I'm using Room database. I'm making network calls in viemwodel, and after fetching data from the api I want to store it in the database. Below is my class which has all the db methods like insert and…
Andrain
  • 872
  • 1
  • 16
  • 43