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

Android tests using sharedViewModel fail with java.lang.ClassCastException androidx.lifecycle.SavedStateHandleController when upgrading Koin to 3.1.3

I'm currently using Koin version 3.1.0 and want to upgrade to the latest version (currently 3.1.4), But once I upgrade Koin to 3.1.3 are above I get the following exception when I run my tests: class java.lang.Object cannot be cast to class…
Wirling
  • 4,810
  • 3
  • 48
  • 78
5
votes
2 answers

Duplicated class Koin org.koin and io.insert-koin

I'm using two library that have dependencies of two different versions of Koin. One of the library has org.koin:koin-android:2.0.1 and the other has io.insert-koin:koin-core-jvm:3.0.1 dependencies. At compile time I got tons of Duplicate class error…
Perihan Mirkelam
  • 526
  • 1
  • 5
  • 18
5
votes
1 answer

WorkManager set up with KOIN

I'm trying to set up work manager to do some work and I'm having trouble initializing it. Im using KOIN workmaanger dsl implementation "org.koin:koin-androidx-workmanager:2.2.0-rc-4" and my worker class looks like this class…
lmiskovic
  • 109
  • 1
  • 10
5
votes
1 answer

Koin's lifecycleScope vs activity.scope. Are they the same?

I'm learning Koin's Scope from https://github.com/InsertKoinIO/koin/blob/master/koin-projects/docs/reference/koin-android/scope.md If I have a Koin module as below val myModule = module { scope { scoped { Presenter() } } …
Elye
  • 53,639
  • 54
  • 212
  • 474
5
votes
2 answers

How to add correctly two modules in koin?

I am developing a news app and I want to add two modules in application class but I am getting the following exception. java.lang.RuntimeException: Unable to create application…
Edgar
  • 860
  • 1
  • 17
  • 38
5
votes
2 answers

Get the same instance of ViewModel in Fragment which is defined in Activity with parameter

So, I am using Koin for dependency injection, Here is what I did inside a activity class ModuleDetailActivity : AppCompatActivity() { private lateinit var moduleId:String private lateinit var levelModule:Level.Module private val…
Hussain
  • 1,243
  • 12
  • 21
5
votes
0 answers

Koin - Problem with nested scopes for Android

Koin Version used : 2.1.0-alpha-8 I have a FeatureActivity that hosts two Fragments 1) FirstFragment and 2) SecondFragment My Module looks like this val featureModule = module { scope { // FeatureDao scoped { …
nitin
  • 123
  • 1
  • 9
5
votes
3 answers

Get sharedviewmodel in childfragment using Koin and navArgs

I have a fragment which basically only holds a bottomnavigation and a viewmodel. This viewmodel is shared by all the childfragments in this fragment. My parentfragment looks a bit like this: class UserDetailFragment : Fragment() { private val…
Typhaon
  • 828
  • 8
  • 27
5
votes
0 answers

Cannot debug Android InstrumentedTest + ActivityScenario + Koin + Mocck

I'm getting the following error when trying to debug androidTests on my device. The only error that appears is the following, and the test hangs forever until I stop it. Test completes ok if I run it, the problem is when I try yo debug it. I have…
5
votes
1 answer

Koin dependency override is not working in testing

I'm new to testing and I adapted Koin as my dependency injection. my application is working fine. it's still having a login function. Here's my dependency class Modules.kt val applicationModule = module (override = true) { single {…
5
votes
0 answers

Android UI Testing with Espresso, Mockito, Koin and Kotlin gives mocking problems

I'm trying to to test my fragment and my test looks like this: @ExperimentalCoroutinesApi @RunWith(AndroidJUnit4::class) @LargeTest class AccountFragmentTest { @Mock private lateinit var repositoryMock: Repository private lateinit var…
noloman
  • 11,411
  • 20
  • 82
  • 129
5
votes
1 answer

Can't run unit tests with RobolectricTestRunner and Koin

I have a test class with RobolectricTestRunner which I use for getting application context and also I extend one class with KoinComponent. When I started my test it returned java.lang.IllegalStateException: KoinApplication has not been started and…
Joks
  • 309
  • 2
  • 17
5
votes
2 answers

Koin injecting into WorkManager

I have a basic work manager class BackgroundSyncWorker ( appContext: Context, workerParams: WorkerParameters ): Worker(appContext, workerParams) { override fun doWork(): Result { return Result.success() } } And I want to…
Daniel Sims
  • 531
  • 4
  • 21
5
votes
6 answers

org.koin.android.error.MissingAndroidContextException: when try to test app with context

I want to write test for koin. I use RoomDatabase, which receives context in constructor. App works well but test fails Can't resolve Application instance. Please use androidContext() function in your KoinApplication configuration.
Nurseyit Tursunkulov
  • 8,012
  • 12
  • 44
  • 78
5
votes
1 answer

Gradle dependency not shared with dependent module

Context I have two modules in my project: Java/Kotlin module common Android/Kotlin module app common depends on Koin, which is a Kotlin library for dependency injection: dependencies { implementation 'org.koin:koin-core:1.0.2' } Usage…
Tijee
  • 388
  • 3
  • 12