57 lines
1.7 KiB
Kotlin
57 lines
1.7 KiB
Kotlin
package be.vandewalleh
|
|
|
|
import be.vandewalleh.controllers.KodeinController
|
|
import be.vandewalleh.controllers.controllerModule
|
|
import be.vandewalleh.features.Feature
|
|
import be.vandewalleh.features.configurationFeature
|
|
import be.vandewalleh.features.configurationModule
|
|
import be.vandewalleh.features.features
|
|
import be.vandewalleh.migrations.Migration
|
|
import com.fasterxml.jackson.databind.SerializationFeature
|
|
import io.ktor.application.Application
|
|
import io.ktor.application.install
|
|
import io.ktor.application.log
|
|
import io.ktor.features.CORS
|
|
import io.ktor.features.ContentNegotiation
|
|
import io.ktor.jackson.jackson
|
|
import io.ktor.locations.Locations
|
|
import io.ktor.routing.routing
|
|
import me.liuwj.ktorm.database.Database
|
|
import org.kodein.di.Kodein
|
|
import org.kodein.di.description
|
|
import org.kodein.di.generic.bind
|
|
import org.kodein.di.generic.instance
|
|
import org.kodein.di.generic.singleton
|
|
import javax.sql.DataSource
|
|
|
|
lateinit var kodein: Kodein
|
|
|
|
@Suppress("unused") // Referenced in application.conf
|
|
fun Application.module() {
|
|
// must be first to be loaded
|
|
configurationFeature()
|
|
|
|
kodein = Kodein {
|
|
import(controllerModule)
|
|
import(configurationModule)
|
|
|
|
bind<Feature>() with singleton { Migration(this.kodein) }
|
|
bind<Database>() with singleton { Database.Companion.connect(this.instance<DataSource>()) }
|
|
}
|
|
|
|
features()
|
|
|
|
log.debug(kodein.container.tree.bindings.description())
|
|
|
|
// TODO, clean this (migration)
|
|
val feature: Feature by kodein.instance()
|
|
feature.execute()
|
|
|
|
val controllers: Set<KodeinController> by kodein.instance()
|
|
|
|
routing {
|
|
controllers.forEach {
|
|
it.apply { registerRoutes() }
|
|
}
|
|
}
|
|
} |