mirror of https://github.com/usbharu/Hideout.git
feat: SPIを使用してModuleContextを読み込むように
This commit is contained in:
parent
a88c23d5cf
commit
4e8126ee06
|
@ -16,11 +16,27 @@
|
|||
|
||||
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 org.bson.UuidRepresentation
|
||||
import org.koin.ksp.generated.module
|
||||
|
||||
class MongoModuleContext : ModuleContext {
|
||||
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
|
||||
|
||||
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.RetryPolicyFactory
|
||||
import dev.usbharu.owl.common.property.PropertySerializerFactory
|
||||
import dev.usbharu.owl.common.property.PropertySerializerFactoryImpl
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.bson.UuidRepresentation
|
||||
import org.koin.core.context.startKoin
|
||||
import org.koin.dsl.module
|
||||
import org.koin.ksp.generated.defaultModule
|
||||
import java.util.*
|
||||
|
||||
fun main() {
|
||||
|
||||
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 moduleContext = ServiceLoader.load(ModuleContext::class.java).first()
|
||||
|
||||
val koin = startKoin {
|
||||
printLogger()
|
||||
|
||||
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> {
|
||||
PropertySerializerFactoryImpl()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue