Hello All, I’m using koin and ktor for my backend ...
# koin
p
Hello All, I’m using koin and ktor for my backend service. The snippet shows my project structure. The code compiles without any warning but while calling the api, I’m getting
org.koin.core.error.NoBeanDefFoundException: |- No definition found for class:'com.company.project.controller.Controller'. Check your definitions!
Can someone please let me know what I’m doing wrong? TIA
m
and where is the part with
startKoin
?
p
@Mustafa Ozhan That part of code is as below:
Copy code
fun main(): Unit = SuspendApp {
    resource {
        val engine = server(Netty).bind()
        engine.application.module()
    }.use { awaitCancellation() }
}

fun Application.module() {
    configureRouting()
    configureHTTP()
    configureMonitoring()
    configureSerialization()
    statusPage()
    configureKoin()
}

fun Application.configureKoin() {
    install(Koin) {
        SLF4JLogger()
        modules(
            networkModules
            serviceModules
            controllerModules
        )
    }
}
m
You should move the
configureKoin
before using any dependency injected by koin,
p
@Mustafa Ozhan I had tried moving configureKoin before configureRouting but it didn’t help.
a
this mean that you are requesting a definition and Koin has not loaded yet your definition
have tried to put
configureKoin()
at top?
p
@arnaud.giuliani yes, it didn’t help
a
if you add
SLF4JLogger()
to DEBUG level
can you track when/where it is loaded?
p
I had done that yesterday, The controller is getting loaded when the server is starting up, but upon calling the api, I’m getting that error. I also have an interceptor service in my actual project and I’m loading them in service modules and they are working fine.
a
weird 🤔 Must spot the difference here
p
The only difference between the interceptor service and controller is that I’m loading the controller via lazy injection but doing it the other way around doesn’t help either and throws the same error while starting up the server.