I tried the reckless move of removing Koin from Kt...
# ktor
m
I tried the reckless move of removing Koin from Ktor... Does that mean everything is handled in the main module,
fun Application.module() {}
? What if Di is removed? I'm curious about what kind of architecture and structure are typically used in real-world or medium-scale projects. I decided to switch because I felt that using Koin was making the middle layer too messy.
a
Removing Koin doesn't mean everything belongs in "Application.module()". I'd recommend using it as your composition root, where dependencies are initialized and passed to feature modules. That's still dependency injection, just without a framework. For medium-sized projects, I'd prefer a feature-based structure with manual DI. If dependency management becomes complex, Ktor also provides a built-in DI plugin. Official docs: https://ktor.io/docs/server-application-structure.html https://ktor.io/docs/server-dependency-injection.html
b
I also wrote a blog post about how modules and our DI plugin works last year that you might find useful in this context https://blog.jetbrains.com/kotlin/2025/07/modular-ktor-building-backends-for-scale/
šŸ’Æ 1
s
Ktor without DI framework was also part of my talk at the last KotlinConf,

youtube.com/watch?v=JOZFZ__3M7Qā–¾

.
m
This might be a slightly off-topic and presumptuous question, but... How should I approach the learning curve for Ktor?
sorry…
b
Do you mean the best approach to learning the framework? It is generally best to read through the documentation and try the tutorials and view the sample projects https://ktor.io/docs/welcome.html
šŸ™Œ 1
šŸ‘€ 1
m
It’s a little different from the tutorial I saw a while back. But do you implement DI using a library? Ktor explicitly supports DI, while Spring uses ā€œmagicā€ annotations—Spring IoC handles it… Ktor seems a bit more complicated to me—maybe because I started with Spring… How would you set it up if you were me…?
b
we’ve got some docs that go over Application structure and Dependency Injection too. If you’re going with DI, I’d recommend listing your modules in the config file and resolving them as module arguments and providing them via other modules in
dependencies { provide {} }
or the
application.dependencies
property. If you’re just getting started with Ktor you can just wire things up manually to get a feel for the routing and the different plugins before you you introduce DI though - it’s not like Spring where DI is foundational knowledge, it’s just an extra optional feature if you need dynamic injection
m
oohhh Thx Sorry for asking this, but do you happen to have any KTOR open-source projects in your GitHub repositories? If so, I’d like to take a look at them.
b
we’ve got a bunch in here for specific use-cases https://github.com/ktorio/ktor-samples/ and you can also check out a larger example with DI and WebRTC https://github.com/ktorio/ktor-chat there’s this one I made a little while ago to demo OpenAPI generation https://github.com/bjhham/ktor-petclinic-rest and Simon’s got some good ones too like https://github.com/nomisRev/ktor-quickstart and https://github.com/nomisRev/ktor-full-stack-real-world we’re working on a new set of demo projects that should be available pretty soon too
m
I’ll definitely check it out. Thanks for your help. I’ll do my best! I want to get out of Spring. T_T
b
this is the correct disposition to have šŸ˜„ kodee loving
m
šŸ‘€Are you a Ktor developer, by any chance??
b
you could say that https://github.com/bjhham
šŸ™Œ 1
m
I feel like I’ve discovered something amazing—it’s so mysterious. When using
Type-safe
instead of the classic method in the
Auth
section, it turns out you have to pass the constructor itself...
authenticateWith(auth)
, right? I had to use this... The classic version was
authenticate(string)
. So, would it be enough to just create a function that returns the
auth
constructor and use it everywhere...? Or how should I use it? I used to write
authenticate(string)
, but this is the first time I’ve seen the constructor itself. Which one should I use?
Classic
? Or
type-safe
?
a
I'd recommend using type-safe authentication, especially for new projects. You're not passing a constructor to "authenticateWith(auth)". You're passing an authentication scheme instance created during configuration. The main advantage over classic "authenticate("name")" is that Ktor knows the principal type, so "call.principal" doesn't require manual casting or null checks. I'd define the scheme once and pass the same instance to your routing modules rather than creating a new one each time. Both approaches are valid and can coexist, but keep in mind that the type-safe API is still experimental.
āž• 1
m
github.com/mrjimin/ktor-auth-test I’d like to have this code reviewed. I was so engrossed in reading the wiki for feedback that I lost track of time. I’ve tried my best to implement it, but it’s proving difficult... I’m trying to implement manual dependency injection. I’d appreciate any feedback. Also, I’d like to extract the
routing
section from
jwtRoutes
and
jwtRoutesWithTypeSafe
and use it in a separate class, such as
AuthRoute
. Is there a way to do that? thx šŸ˜„