https://kotlinlang.org logo
#koin
Title
# koin
j

Jerry Preissler

09/24/2023, 7:07 PM
Ok, I'm running into a problem when upgrading from io.insert-koinkoin ktor3.4.3 to 3.5.1 (details in thread). Maybe someone can point me to some documentation what I need to do or give some hints?
I'm working on a ktor project using koin. I simply updated io.insert-koinkoin ktor3.4.3 to 3.5.1 without any code changes and get the following error when trying to access an injected property in my KoinComponent:
Copy code
java.lang.IllegalStateException: KoinApplication has not been started
	at org.koin.core.context.GlobalContext.get(GlobalContext.kt:36)
	at org.koin.core.component.KoinComponent$DefaultImpls.getKoin(KoinComponent.kt:33)
	at org.codeshards.aktenordner.application.service.ListDokumenteService.getKoin(ListDokumenteService.kt:10)
Here is the part in my Application where I install Koin:
Copy code
fun Application.module() {
    dokumentModule()
    configureRouting()
    install(Koin) {
        slf4jLogger()
        modules(
            restKoinModule,
            filePersistenceKoinModule
        )
    }
}
And here is the KoinModule in question:
Copy code
import org.codeshards.aktenordner.application.port.incoming.GetDokumentUseCase
import org.codeshards.aktenordner.application.service.ReadDokumentService
import org.codeshards.aktenordner.application.service.CreateDokumentService
import org.codeshards.aktenordner.application.service.ListDokumenteService
import org.codeshards.aktenordner.application.service.UploadDokumentContentService
import org.codeshards.aktenordner.application.port.incoming.CreateDokumentUseCase
import org.codeshards.aktenordner.application.port.incoming.ListDokumenteUseCase
import org.codeshards.aktenordner.application.port.incoming.UploadDokumentContentUseCase
import org.koin.dsl.module
import org.koin.core.module.dsl.singleOf
import org.koin.core.module.dsl.bind

val restKoinModule = module {
    singleOf(::CreateDokumentService) {
        bind<CreateDokumentUseCase>()
    }
    singleOf(::ReadDokumentService) {
        bind<GetDokumentUseCase>()
    }
    singleOf(::ListDokumenteService) {
        bind<ListDokumenteUseCase>()
    }
    singleOf(::UploadDokumentContentService) {
        bind<UploadDokumentContentUseCase>()
    }
}
Any hints would be greatly appreciated.
p

Pedro Francisco de Sousa Neto

09/25/2023, 1:14 PM
I think startKoin is missing.
j

Jerry Preissler

09/25/2023, 1:48 PM
Thank you for the pointer, I'll give it a try tonight. On first glance it looks like the method of starting Koin from the Ktor server does not work anymore.
p

Pedro Francisco de Sousa Neto

09/26/2023, 1:18 PM
Did it worked, @Jerry Preissler?
j

Jerry Preissler

09/28/2023, 6:23 AM
@Pedro Francisco de Sousa Neto Sorry for the late reply, work interfered. I'll have to postpone this until the next weekend. One thing I noticed was that the example you linked to is using an older version of Koin. So my plan right now is to get the example running locally and see what happens when I try to go to the current Koin version.
p

Pedro Francisco de Sousa Neto

09/28/2023, 12:36 PM
Hum… I didn’t knew about that. If you can’t make it run, please share with us in this thread. ;)
And if you make it run, too. It’s always good hear some good news :)
j

Jerry Preissler

10/02/2023, 10:02 AM
Short intermediate update: after updating to Koin 3.5.0 the Ktor + Koin + MongoDB backend template still seems to be working. So I'll restructure my app to the layout provided there. Will update when this is done.
🚀 1
2 Views