Skip to content

Instantly share code, notes, and snippets.

@mathias21
Last active August 3, 2020 21:59
Show Gist options
  • Save mathias21/1532a9c08b07f390b05a127df335690d to your computer and use it in GitHub Desktop.
Save mathias21/1532a9c08b07f390b05a127df335690d to your computer and use it in GitHub Desktop.
KtorEasy controller testing: base controller
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