Last active
August 3, 2020 21:59
-
-
Save mathias21/1532a9c08b07f390b05a127df335690d to your computer and use it in GitHub Desktop.
KtorEasy controller testing: base controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class BaseController : KoinComponent { | |
private val dbProvider by inject<DatabaseProviderContract>() | |
suspend fun <T> dbQuery(block: () -> T): T { | |
return dbProvider.dbQuery(block) | |
} | |
} | |
class DatabaseProvider : DatabaseProviderContract, KoinComponent { | |
private val dispatcher: CoroutineContext | |
[...] | |
override suspend fun <T> dbQuery(block: () -> T): T = withContext(dispatcher) { | |
transaction { block() } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment