amazingustav
05/08/2020, 10:40 PMApplicationContext
as parameter…
That’s my class:
class Foo(environment: ApplicationEnvironment) { ... }
That’s the class which calls Foo
:
class Bar(private val foo: Foo) { ... }
And that’s my KoinModuleBuilder
:
object KoinModuleBuilder {
fun modules() = listOf(module {
single {
Foo(get())
Bar(get())
}
})
}
And finally, that’s the error: org.koin.error.NoBeanDefFoundException: No compatible definition found for type 'ApplicationEnvironment'
aipok
05/10/2020, 3:09 PMapplicationContext
you should use
androidContext()
function instead of get()
call. Also what is ApplicationEnvironment
means? Is it your application class name? If yes, you can get instance of your application using androidApplication()
method. But in this case you need to change your parameter class to Application
and cast in inside your Foo class to correct name. Or make another single that will call androidApplication() as ApplicationEnvironment
.amazingustav
05/11/2020, 3:08 PMApplicationEnvironment
is a Ktor component that allows to get environment variables.aipok
05/11/2020, 3:10 PMamazingustav
05/11/2020, 3:18 PMaipok
05/11/2020, 3:43 PMkoin-ktor
module sources I don’t see any reference that could trigger me something. Might be @arnaud.giuliani could suggest something he is very kind person 😉arnaud.giuliani
05/11/2020, 4:10 PMApplicationEnvironment
from Ktor?amazingustav
05/11/2020, 4:10 PMarnaud.giuliani
05/11/2020, 4:21 PMApplicationContext
in android with androidContext( ... )
DSL extensionarnaud.giuliani
05/12/2020, 7:48 AMamazingustav
05/12/2020, 5:42 PMamazingustav
05/12/2020, 6:13 PMinstallKoin(modulesAsList)
. In that case, as I get Koin modules by a function, I solved that just passing environment
context to it, while inside Ktor main class, like below:
// Ktor module
fun Application.module() {
installKoin(KoinModuleBuilder.modules(this.environment))
// others installations
install { ... }
}
// Koin module builder
object KoinModuleBuilder {
fun modules(applicationEnvironment: ApplicationEnvironment) = listOf(module {
single { applicationEnvironment }
...
...
})
}
Thank you Vitali and Arnaud to every help!arnaud.giuliani
05/13/2020, 9:09 AMarnaud.giuliani
05/13/2020, 10:07 AM