Is it possible to define routes across multiple cl...
# ktor
v
Is it possible to define routes across multiple classes/files? Reading the docs https://ktor.io/servers/structure.html#deployment-and-applicationconf I think I'd have to create multiple top-level Routing functions, e.g
Copy code
fun Routing.customer() { get("/customer") {... } }
and
Copy code
fun Routing.admin() { get("/admin") {...} }
and then call each of them inside
Copy code
Application.mainModule() ...
? Any way of using classes instead of top-level functions?
h
Out of curiosity, why do you want them inside a class?
m
Yes; I show how to do this with Guice-managed classes here: https://bitbucket.org/marshallpierce/ktor-demo
v
Familiarity. Every other framework I've ever used puts routes in classes... Spring, SparkJava, JSF (kinda...).
h
Ah. You can always move them in different files for sure. I didn't try putting routes in a class myself yet.
m
Having them in classes gets convenient when the handler logic gets more complex. TMTOWTDI but I prefer to have classes so that there’s something for a DI container to inject into.
h
I did
Routing.method(args) = route
extensions in various files for the various paths, and the args are things like a single DAO. Didn't use injections yet. Thanks for the sample!
v
I found a pull request which is close to my use case: https://github.com/ktorio/ktor/pull/706