1

I've a multi-module project & I'm facing some weird issues setting up Koin DI. My project has following modules: app, library.

I've declared an interface in library module & its corresponding implementation in app module & I want to use the same in library. The code looks somewhat like:

Library Module:

interface Storage {
    fun setUser(user: User)
    fun getUser(): User
}

App Module:

class MyApplication : Application() {

    override fun onCreate() {
        super.onCreate()
        startKoin(this, listOf(appModule))
} 


val appModule = module {
    single<Storage> { AppStorage(androidApplication()) }
}

Now, when I try to inject Storage in library module, I get NoBeanDefFoundException. Below is the code for the same:

class LibActivity {

    private val storage by inject<Storage>()
    ...
}

Any ideas on what is wrong with the above code?

Gaurav Arora
  • 17,124
  • 5
  • 33
  • 44
  • Should work something like that. What version of koin are you using? The `startKoin` syntax looks like koin 1; koin 2 is also available. – laalto Oct 25 '19 at 06:51
  • @Gaurav Arora, Were you able to fix the issue, please let me know – Reprator Jun 18 '20 at 19:06

0 Answers0