Skip to content

Commit

Permalink
fix: do not user route installer bean
Browse files Browse the repository at this point in the history
  • Loading branch information
d1snin committed Mar 25, 2024
1 parent 7921777 commit 4b75a3b
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 287 deletions.
12 changes: 0 additions & 12 deletions exkt-ktor-server-koin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,5 @@ kotlin {
implementation(project(":exkt-common"))
}
}

val jvmTest by getting {
dependencies {
val mockkVersion: String by project

val koinVersion: String by project

implementation(kotlin("test-junit"))
implementation("io.mockk:mockk:$mockkVersion")
implementation("io.insert-koin:koin-test:$koinVersion")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,13 @@ package dev.d1s.exkt.ktor.server.koin.configuration

import dev.d1s.exkt.common.withEach
import io.ktor.server.routing.*
import org.koin.core.component.KoinComponent
import org.koin.core.context.GlobalContext

internal interface RouteInstaller {
private val routes
get() = GlobalContext.get().getAll<Route>()

fun Routing.installRoutes()
}

internal class DefaultRouteInstaller : RouteInstaller, KoinComponent {

private val routes by lazy {
getKoin().getAll<Route>()
}

override fun Routing.installRoutes() {
routes.withEach {
apply()
}
internal fun Routing.installRoutes() {
routes.withEach {
apply()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ import io.ktor.server.config.*
import io.ktor.server.engine.*
import io.ktor.server.routing.*
import org.koin.core.component.KoinComponent
import org.koin.core.component.get
import org.koin.core.error.NoBeanDefFoundException
import org.koin.core.module.Module
import kotlin.getValue
import kotlin.lazy
import kotlin.with
import org.koin.dsl.module as koinModule

public typealias Configurers = List<Configurer<*>>
Expand Down Expand Up @@ -111,12 +109,8 @@ public abstract class ServerApplication : KoinComponent {

private fun Application.installRoutes() {
try {
val routeInstaller = get<RouteInstaller>()

routing {
with(routeInstaller) {
installRoutes()
}
installRoutes()
}
} catch (_: NoBeanDefFoundException) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@

package dev.d1s.exkt.ktor.server.koin.configuration.builtin

import dev.d1s.exkt.ktor.server.koin.configuration.DefaultRouteInstaller
import dev.d1s.exkt.ktor.server.koin.configuration.Route
import dev.d1s.exkt.ktor.server.koin.configuration.RouteInstaller
import org.koin.core.module.Module

public class Routes internal constructor() : MutableList<Route> by mutableListOf() {
Expand All @@ -27,7 +25,7 @@ public class Routes internal constructor() : MutableList<Route> by mutableListOf
}

/**
* Supposed to be used in [Configurers][dev.d1s.exkt.ktor.server.koin.configuration.Configurer] to configure routes.
* Supposed to be used in [Configturers][dev.d1s.exkt.ktor.server.koin.configuration.Configurer] to configure routes.
*/
public fun Module.configureRoutes(builder: Routes.() -> Unit) {
val routes = Routes().apply(builder)
Expand All @@ -37,8 +35,4 @@ public fun Module.configureRoutes(builder: Routes.() -> Unit) {
route
}
}

single<RouteInstaller> {
DefaultRouteInstaller()
}
}

This file was deleted.

This file was deleted.

0 comments on commit 4b75a3b

Please sign in to comment.