ursus
08/31/2023, 9:06 PMfun main() {
embeddedServer(Netty, port = 8000) {
routing {
get ("/") {
call.respondText("Hello, world!")
}
}
}.start(wait = true)
}
What is the ktor idiomatic way to scale this? The functional style trips me up.
fun Route.root() {
get ("/") {
myLogic()
call.respondText("Hello, world!")
}
}
suspend fun myLogic() {
...
}
something like this?
if so, how do I then participate in DI?
fun Route.root(graph: DI) {
get ("/") {
val myService = graph.get<MyService>()
myService.myLogic()
call.respondText("Hello, world!")
}
}
class MyService {
suspend fun myLogic() {
...
}
}
like this?Berkay Özkan
09/01/2023, 7:20 AMBerkay Özkan
09/01/2023, 7:20 AMfun Application.main() {
// Lazy inject HelloService
val service by inject<UserService>()
// Routing section
routing {
get("/hello") {
call.respondText(service.sayHello())
}
}
}