I see withTestApplication is deprecated, but I'm n...
# ktor
b
I see withTestApplication is deprecated, but I'm not sure how to pass in my Guice injector without providing the ApplicationEngineEnvironment directly. Is there a way to do so without using deprecated methods?
Copy code
val injector = Guice.createInjector(modules)
env = injector.getInstance(ApplicationEngineEnvironment::class.java)
Copy code
@Test
 fun greetingApiTest() = withApplication(env!!) {
...
If anybody knows why https://ktor.io/docs/guice.html and a bunch of other sample ktor+guice code is 404 now, I would be curious to know the reason. aka https://github.com/ktorio/ktor-samples/tree/main/guice-sample
Even the ktor-guice plugin is gone from Maven.
a
Can't speak for the official reason, but it might be because: • DI frameworks might be considered obsolete/anti-pattern in Kotlin • Guice may be deprecated in favor of kotlin-oriented frameworks like KOIN, or for compile-time frameworks like Dagger 2
b
Thanks. After fighting with Guice a bunch I am looking into KOIN and will check out Dagger 2. When you mention they may be an anti-pattern, do you mean DI frameworks, or dependency injection in general w.r.t. Kotlin?
a
I refer to the framework. The DI pattern is still widely seen as excellent to make OO code more testable and maintainable. Opinion: Kotlin (as opposed to Java) doesn't need a framework to achieve good DI, except in perhaps the most egregious of monoliths.
b
This is my first Kotlin program past hello world so I have a lot to learn about the language features, coming from Java. It is just a toy project so perf isn’t a concern if a DI framework makes my life any easier. I can’t say Guice did though.
a
Good luck!