Hello. Have anyone implemented a rest api or micro...
# server
l
Hello. Have anyone implemented a rest api or microservice using ktor, any dependency injection framework as koin, ddd and clean architecture?
b
github.com/mpetuska/hazelcast-explorer uses kodein, but is nowhere near clean architecture 😄
j
We use Ktor/Guice and have controller classes responsible for installing a set of routes, and handling request parsing, delegating to the relevant service and setting status code. We test these with API tests only, firing requests at a TestApplicationEngine with mocked out services, configured with a test Guice injector (used by all tests). Depends how strictly you define "clean architecture" I guess. Bit boilerplatey setting up a new backend but once done feels clean enough for agile development.
l
@Big Chungus thanks! I will take a look
@Jonathan Mew thanks for the info! Does your controller class extends from some class of ktor or your routing function call the controller?
m
we use ktor + koin, routing function calls the controller, controller calls the usecase, be aware of how koin reuses instances of your classes for more than one rq.
j
No, our controllers don't subclass anything. We have a class to do application configuration which has all controllers (and the application) injected, and we install each controllers' routes in turn there. Using kotlin-guice for injection
p
We just did the injection ourselves because it was a migration from an existing development using lazy instances. Meant that the start-up was very quick and was easy to still mock for our unit tests.
j
Yep I used Koin and some clean archi concepts in the sample I built here : https://github.com/Oleur/swcook-ktor-api
l
great
thanks all!
d
Micronaut has a module to support Ktor, and has a fullblown DI system (after that we ended up just switching to Micronaut, though... partly for this concern)