Mohammed Toufeeq Ahamed
09/30/2023, 6:09 PMsimon.vergauwen
10/02/2023, 10:22 AMapplication.enviroment.monitor(ApplicationStopping)
,
or addShutdownHook { }
.
Afaik Ktor-koin doesn't automatically take into account AutoCloseable
like Spring does, so when using koin-ktor
you still need to manually take care of this.
I'm curious if there are other options, SuspendApp
and Resource
are more general than just Ktor though. You can also use it in CLI applications, for producing/consuming records from Kafka for example.Mohammed Toufeeq Ahamed
10/03/2023, 5:26 AMsimon.vergauwen
10/03/2023, 6:38 AMResource
is really great 😅 It's a typed (compile-time) version of what Spring does with runtime introspection / reflection.
To be honest, I rather call it ResourceScope
, and I see it as CoroutineScope
. That's also how I explain it in my talk, .
I also have an example here, https://github.com/nomisRev/ktor-arrow-example/blob/main/src/main/kotlin/io/github/nomisrev/env/Dependencies.kt.
So in every module you can expose suspend fun ResourceScope.dependency(): A
for "structured resources" and then you can call these functions, similarly how you do fun CoroutineScope.concurrency(): A
for structured concurrency.
I've considered splitting ResourceScope
completely from Arrow, so you don't have any additional dependencies coming in. So you can just use SuspendApp
and Resource
without anything else from Arrow on the classpath. Would that lower the threshold for people to use it? 🤔Mohammed Toufeeq Ahamed
10/03/2023, 6:56 AMsimon.vergauwen
10/03/2023, 6:57 AMsimon.vergauwen
10/03/2023, 6:57 AMMohammed Toufeeq Ahamed
10/03/2023, 6:59 AMsimon.vergauwen
10/03/2023, 7:01 AM@AutoWired
where in App
module you don't touch any code from Service
module.
Somewhere there is some code constructing service
and repository
because those are dependencies of UseCase
, right? Which are probably hiding the dependencies?Mohammed Toufeeq Ahamed
10/03/2023, 7:10 AMenvironment.monitor.subscribe(KoinApplicationStarted) {
<http://log.info|log.info>("Koin started.")
}
But again these are dependent on Application's context
simon.vergauwen
10/03/2023, 7:15 AMapplication.enviroment.monitor(ApplicationStopping)
.simon.vergauwen
10/03/2023, 7:17 AM