Closed lukelast closed 10 months ago
I haven't tried it yet. I'll check it out and let you know in a few days, when I get back from vacation.
It works fine for me. This is what you need to do:
backendMain
sources set:
val backendMain by getting {
dependencies {
// ...
implementation("io.insert-koin:koin-annotations:1.2.2")
}
kotlin.srcDir("build/generated/ksp/backend/backendMain/kotlin")
}
build.gradle.kts
file add KSP configuration:
dependencies {
add("kspBackend", "io.insert-koin:koin-ksp-compiler:1.2.2")
}
afterEvaluate { tasks { getByName("kspKotlinBackend").apply { dependsOn("kspCommonMainKotlinMetadata") } } }
3. Declare annotated module:
```kotlin
package com.example
import io.ktor.server.application.*
import io.ktor.server.plugins.compression.*
import io.ktor.server.routing.*
import io.kvision.remote.applyRoutes
import io.kvision.remote.getAllServiceManagers
import io.kvision.remote.kvisionInit
import org.koin.core.annotation.ComponentScan
import org.koin.core.annotation.Module
import org.koin.ksp.generated.module
@Module
@ComponentScan("com.example")
class PingModule
fun Application.main() {
install(Compression)
routing {
getAllServiceManagers().forEach { applyRoutes(it) }
}
kvisionInit(PingModule().module)
}
@Factory
annotation to the service class:
import org.koin.core.annotation.Factory
@Suppress("ACTUAL_WITHOUT_EXPECT") @Factory actual class PingService : IPingService {
override suspend fun ping(message: String): String {
println(message)
return "Hello world from server!"
}
}
I'm not able to get it working on template-fullstack-ktor-koin
When trying to place the blok:
dependencies {
add("kspBackend", "io.insert-koin:koin-ksp-compiler:1.2.2")
}
If I put it before jvm("backend")
then I get the error Configuration with name 'kspBackend' not found
.
If I put it after, I get the error Cannot change hierarchy of dependency configuration ':backendCompilationApi' after it has been included in dependency resolution
.
Any ideas?
You are right. I was doing my tests with a snapshot version of KVision, which uses new version of KSP. Unfortunately I'm also unable to make it work with current KVision. KVision 7 will be released in a few days and I'll add ktor-annotations template to the examples repository.
Awesome thank you!
It would be great to have Koin Annotations, even if just for the backend. https://insert-koin.io/docs/reference/koin-annotations/start
I wasn't able to get them working on this project: https://github.com/rjaros/kvision-examples/blob/master/template-fullstack-ktor-koin/build.gradle.kts
Do you think it's possible?