https://kotlinlang.org logo
#ktor
Title
# ktor
h

Henry

05/26/2021, 12:18 AM
I guess this has been asked before but I'm at a bit of a loose end. I'm adding transaction support to my ktor application and currently have an implementation that works like this:
Copy code
// All db calls in this block will be executed within a transaction, on a connection held in the coroutine context
transactional {
    ...
}
As it stands it requires a call to a static method on application startup to initialise a tx manager which the
transactional
call then uses to execute the tx. This is hard to test. I'd instead like to inject a transaction manager into a parent coroutine context so it's available everywhere in the app without needing to initialise it via a static method. I looked at using a feature that intercepts the application pipeline to do this but I don't think it does what I need. Any ideas?
r

Rustam Siniukov

05/26/2021, 1:17 PM
If you use
embeddedServer
, you can pass
parentCoroutineContext
as parameter. But it’s not possible with
EngineMain
currently. I created a ticket for this https://youtrack.jetbrains.com/issue/KTOR-2733
👍 1
h

Henry

05/26/2021, 10:57 PM
useful to know, thanks a lot!
2 Views