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

java.lang.NoClassDefFoundError: Failed resolution of: Lkotlin/time/MonoClock

I have recently updated the version of Kotlin to 1.3.70 in my Android project. Since then Koin (version: 2.1.0-beta-1 ) is giving me the run time error below: java.lang.NoClassDefFoundError: Failed resolution of: Lkotlin/time/MonoClock;
Aydinozkan
  • 2,508
  • 2
  • 21
  • 26
15
votes
6 answers

How to use Koin in multiple module?

There are two modules in my android project, app module and lib module. Both these two modules need Koin for D.I., so I call startKoin in MyApplication class in app module, and IninKointContentProvider in lib module as below. // app module class…
aiueoH
  • 728
  • 1
  • 8
  • 24
15
votes
4 answers

Koin Android: org.koin.error.NoBeanDefFoundException

Got that message error java.lang.RuntimeException: Unable to create application com.app.name.application.MainApplication: org.koin.error.BeanInstanceCreationException: Can't create bean Bean[class=com.app.name.general.preferences.Preferences] due to…
Andrey Danilov
  • 6,194
  • 5
  • 32
  • 56
15
votes
6 answers

Inject Koin in Java classes

I'm trying to replace Dagger 2 to Koin in my current project and I don't want to rewrite some classes in Kotlin to use it. Is possible to inject with Koin in java classes? In Kotlin is just // Inject MyPresenter val presenter : MyPresenter by…
Rafa Araujo
  • 314
  • 1
  • 2
  • 9
14
votes
1 answer

Android, Can't access ViewModels from detached fragment

Every time I rotate my phone, it crashes and prints strange exception in SearchResultFragment no matter isDetached value is false: java.lang.IllegalStateException: Can't access ViewModels from detached fragment in this part of code: private val…
Oktawian
  • 334
  • 1
  • 2
  • 16
14
votes
2 answers

How to inject dependency using koin in top level function

I have top-level function like fun sendNotification(context:Context, data:Data) { ...//a lot of code here } That function creates notifications, sometimes notification can contain image, so I have to download it. I`m using Glide which is…
Andrey Danilov
  • 6,194
  • 5
  • 32
  • 56
13
votes
2 answers

Clearing sharedViewModel

I am using Koin for injecting viewModel into fragment. My app is single activity. I need that sharedViewModel only in servisFragment and partFragment. I would like to clear that viewModel from Activity after navigation marked with red. How can I do…
solaza
  • 1,251
  • 1
  • 17
  • 30
12
votes
2 answers

Could not find org.koin:koin-core:2.2.2

I have recently removed jcenter() repository from the project-level build Gradle. Since then Koin (version: 2.2.2) started giving me the compile-time error below: Could not find org.koin:koin-core:2.2.2
Aydinozkan
  • 2,508
  • 2
  • 21
  • 26
12
votes
3 answers

Koin: NoBeanDefFoundException, Check your module definitions

The koin test results as follows: org.koin.core.error.NoBeanDefFoundException: No definition found for '' has been found. Check your module definitions. the class EmailValidatorUtilImpl is well implemented, import…
Faisal
  • 1,332
  • 2
  • 13
  • 29
11
votes
2 answers

Koin inject viewmodel into Composable

I am trying to use Koin to inject my viewModel (which has some dependencies as well) like this: I don't understand why it cannot find getViewModel when I have the following import: I am using this Koin version: implementation…
FailedUnitTest
  • 1,637
  • 3
  • 20
  • 43
11
votes
1 answer

Android/Koin - How to tell koin that a single dependency should be reinitialized

I stumbled across a problem where I have to reinitialize my Retrofit API class because the URL changes, so I want to tell Koin to reinitialize the single dependency. I don't want to use factory because it is still a singleton most of the…
kaulex
  • 2,921
  • 3
  • 11
  • 38
11
votes
2 answers

Please use override option or check for definition, koin android?

I am implementing Koin DI in my android application. I was successfully able to create some of the modules. However I got an exception where I tried to get object from another in module. These are my modules val networkModule = module { factory {…
WISHY
  • 11,067
  • 25
  • 105
  • 197
11
votes
1 answer

How to inject viewmodel in a customView with koin?

I know how to inject viewmodel in Activities or Fragments with koin: private val regionSelectorViewModel: RegionSelectorViewModel by viewModel() Right now I am setting viewmodel to my customView like this: fun setViewModel(viewModel:…
11
votes
7 answers

KoinAppAlreadyStartedException: A Koin Application has already been started

Using koin-2.0.1 for Android testing and unable to test all 3 test together though each test passes separately. class NumberFormatterUtilImplTest : KoinTest { private val numberFormatterUtil: NumberFormatterUtilImpl by inject() @Before …
Faisal
  • 1,332
  • 2
  • 13
  • 29
11
votes
1 answer

Koin - how to provide mock ViewModel for espresso test?

How can we inject mocked viewModel into Activity for espresso test? Using declareMock I get mock object in Test class but Activity receives regular viewModel object. @RunWith(AndroidJUnit4::class) class SomeActivityTest : KoinTest { @Rule …
1
2
3
32 33