I guess this has been asked before but I'm at a bi...
# ktor
h
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
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
useful to know, thanks a lot!