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

How to use logger with Koin?

Koin version: 2.1.5 Instructions are missing from documentation here. This is what I have: class MyApp : Application() { override fun onCreate() { super.onCreate() startKoin { // use AndroidLogger as Koin Logger -…
ericn
  • 12,476
  • 16
  • 84
  • 127
3
votes
2 answers

Can I unit test Koin Modules?

I'm using Koin as my DI framework in an Android project and I want to unit test my modules. For example: if a class A depends on B and C, test that B and C are being included in the Koin graph and that I'm properly injecting them in the module. Is…
Rod
  • 424
  • 2
  • 7
  • 17
3
votes
1 answer

Koin mocking suspend function

Can anybody tell me if/how I can mock a supend funktion with koin test? The only thing I know so far is this behavior declareMock<...> { given(..)).willReturn(...) } but this doesn't work on suspend fun(). Is there anything similar to…
Wolfgang
  • 481
  • 1
  • 4
  • 6
3
votes
1 answer

How to Unit Test MVVM with Koin?

How to Unit Test MVVM with Koin ? i've try to testing : link But, i don't know why i get error("No Data in ViewModel") in ViewModelTest fun getLookUpLeagueList() Repository class LookUpLeagueRepository { fun getLookUpLeague(idLeague: String):…
Afdal
  • 501
  • 9
  • 19
3
votes
1 answer

Koin java.lang.NoClassDefFoundError: Failed resolution of: Lorg/koin/dsl/context/ParameterHolderKt

I have a simple Android project with MVVM and I am using Koin. These are the versions and dependencies that I have in gradle: build.gradle // Koin implementation "org.koin:koin-core:2.0.1" implementation "org.koin:koin-android:2.0.1" implementation…
Laura
  • 2,653
  • 7
  • 37
  • 59
3
votes
2 answers

Koin - single instance per parameter value

I have a module: single{ (name: String) -> Person(name) } When I do: val alice: Person by inject {parametersOf("Alice")} val bob: Person by inject {parametersOf("Bob")} I get 2 instances of Alice. All parameters other than the first are…
Agent_L
  • 4,960
  • 28
  • 30
3
votes
0 answers

Why does dependency injection not work when using the Koin library in Kotlin project

I am trying to bind this Webtrekk library (https://github.com/Webtrekk/webtrekk-android-sdk-BETA) for Android Webtrekk SDK is written in Kotlin and uses Koin for dependency injection. I am able to create biding and build it successfully but when I…
3
votes
1 answer

How to change base URL using retrofit2 and koin 2.0

I have a query that returns a list of servers, and the user can select the server he needs. Googling did not help, almost no results. Tell me how to implement basic URL spoofing in real time using Koin and Retrofit? My Modules: fun…
3
votes
2 answers

Pass App context to Koin from Java Application class

I have a Java application class, I cannot change it to Kotlin. I init Koin like this: KoinApplication koinApp = KoinApplication.create() .printLogger() .modules( myModule ); …
peresisUser
  • 1,680
  • 18
  • 23
3
votes
2 answers

how to inject View model using koin? (for specific use case)

I am having a shared View Model for activity and it's fragment. My view model need's argument to be passed when instantiating from the activity(onCreate only once) viewModel =ViewModelProviders.of(this, …
Anmol
  • 8,110
  • 9
  • 38
  • 63
3
votes
1 answer

findNavController with a DI tool

I have a single activity and multiple fragments styled application using the navigation component. I am using Koin for my DI. I was wanting to create a Navigator class in my application as per the postulates of clean architecture. This hypothetical…
3
votes
1 answer

Koin injection from constructor in Kotlin

I can't call inject from constructor for my project via Koin DI. If I use "... by inject()" for injection the DataRepository class, all works perfectly. But I want to provide inject in a constructor of a class. I have a crash in the…
3
votes
1 answer

How to inject a repo into FirebaseMessagingService class

I want to send client FCM token to my server when the token is ready, so I need my user repository in MyFirebaseMessagingService. The problem is FirebaseMessagingService needs default empty constructor. So How can inject my userRepo in the…
FarshidABZ
  • 3,860
  • 4
  • 32
  • 63
3
votes
2 answers

How can I use Koin to inject in a @BeforeClass static method?

I have an integration test that needs to call a REST service to get an access token one time before any subsequent tests are run. Before adding Koin to my project, I accomplished this in a static method annotated with @BeforeClass like so: class…
Big McLargeHuge
  • 14,841
  • 10
  • 80
  • 108
3
votes
3 answers

How do I use custom configuration in Ktor?

I'm digging the built-in configuration support, and want to use it (instead of just rolling my own alongside Ktor's), but I'm having a hard time figuring out how to do it in a clean way. I've got this, and it's working, but it's really ugly and I…
Phil Kulak
  • 6,960
  • 8
  • 45
  • 50