feat: SPIを使用してModuleContextを読み込むように
This commit is contained in:
parent
8f5c1715c3
commit
ac6b55e796
|
@ -16,11 +16,27 @@
|
||||||
|
|
||||||
package dev.usbharu.owl.broker.mongodb
|
package dev.usbharu.owl.broker.mongodb
|
||||||
|
|
||||||
|
import com.mongodb.ConnectionString
|
||||||
|
import com.mongodb.MongoClientSettings
|
||||||
|
import com.mongodb.kotlin.client.coroutine.MongoClient
|
||||||
import dev.usbharu.owl.broker.ModuleContext
|
import dev.usbharu.owl.broker.ModuleContext
|
||||||
|
import org.bson.UuidRepresentation
|
||||||
import org.koin.ksp.generated.module
|
import org.koin.ksp.generated.module
|
||||||
|
|
||||||
class MongoModuleContext : ModuleContext {
|
class MongoModuleContext : ModuleContext {
|
||||||
override fun module(): org.koin.core.module.Module {
|
override fun module(): org.koin.core.module.Module {
|
||||||
return MongoModule().module
|
val module = MongoModule().module
|
||||||
|
module.includes(org.koin.dsl.module {
|
||||||
|
single {
|
||||||
|
val clientSettings =
|
||||||
|
MongoClientSettings.builder()
|
||||||
|
.applyConnectionString(ConnectionString("mongodb://agent1.build:27017"))
|
||||||
|
.uuidRepresentation(UuidRepresentation.STANDARD).build()
|
||||||
|
|
||||||
|
|
||||||
|
MongoClient.create(clientSettings).getDatabase("mongo-test")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return module
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
dev.usbharu.owl.broker.mongodb.MongoModuleContext
|
|
@ -16,40 +16,23 @@
|
||||||
|
|
||||||
package dev.usbharu.owl.broker
|
package dev.usbharu.owl.broker
|
||||||
|
|
||||||
import com.mongodb.ConnectionString
|
|
||||||
import com.mongodb.MongoClientSettings
|
|
||||||
import com.mongodb.kotlin.client.coroutine.MongoClient
|
|
||||||
import dev.usbharu.owl.broker.service.DefaultRetryPolicyFactory
|
import dev.usbharu.owl.broker.service.DefaultRetryPolicyFactory
|
||||||
import dev.usbharu.owl.broker.service.RetryPolicyFactory
|
import dev.usbharu.owl.broker.service.RetryPolicyFactory
|
||||||
import dev.usbharu.owl.common.property.PropertySerializerFactory
|
import dev.usbharu.owl.common.property.PropertySerializerFactory
|
||||||
import dev.usbharu.owl.common.property.PropertySerializerFactoryImpl
|
import dev.usbharu.owl.common.property.PropertySerializerFactoryImpl
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import org.bson.UuidRepresentation
|
|
||||||
import org.koin.core.context.startKoin
|
import org.koin.core.context.startKoin
|
||||||
import org.koin.dsl.module
|
import org.koin.dsl.module
|
||||||
import org.koin.ksp.generated.defaultModule
|
import org.koin.ksp.generated.defaultModule
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
fun main() {
|
fun main() {
|
||||||
|
val moduleContext = ServiceLoader.load(ModuleContext::class.java).first()
|
||||||
val moduleContext =
|
|
||||||
Class.forName("dev.usbharu.owl.broker.mongodb.MongoModuleContext").newInstance() as ModuleContext
|
|
||||||
|
|
||||||
|
|
||||||
// println(File(Thread.currentThread().contextClassLoader.getResource("dev/usbharu/owl/broker/mongodb").file).listFiles().joinToString())
|
|
||||||
|
|
||||||
val koin = startKoin {
|
val koin = startKoin {
|
||||||
printLogger()
|
printLogger()
|
||||||
|
|
||||||
val module = module {
|
val module = module {
|
||||||
single {
|
|
||||||
val clientSettings =
|
|
||||||
MongoClientSettings.builder()
|
|
||||||
.applyConnectionString(ConnectionString("mongodb://agent1.build:27017"))
|
|
||||||
.uuidRepresentation(UuidRepresentation.STANDARD).build()
|
|
||||||
|
|
||||||
|
|
||||||
MongoClient.create(clientSettings).getDatabase("mongo-test")
|
|
||||||
}
|
|
||||||
single<PropertySerializerFactory> {
|
single<PropertySerializerFactory> {
|
||||||
PropertySerializerFactoryImpl()
|
PropertySerializerFactoryImpl()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue