diff --git a/broker/broker-mongodb/src/main/kotlin/dev/usbharu/owl/broker/mongodb/MongoModuleContext.kt b/broker/broker-mongodb/src/main/kotlin/dev/usbharu/owl/broker/mongodb/MongoModuleContext.kt index 0fa424d3..6a374362 100644 --- a/broker/broker-mongodb/src/main/kotlin/dev/usbharu/owl/broker/mongodb/MongoModuleContext.kt +++ b/broker/broker-mongodb/src/main/kotlin/dev/usbharu/owl/broker/mongodb/MongoModuleContext.kt @@ -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 } } \ No newline at end of file diff --git a/broker/broker-mongodb/src/main/resources/META-INF/services/dev.usbharu.owl.broker.ModuleContext b/broker/broker-mongodb/src/main/resources/META-INF/services/dev.usbharu.owl.broker.ModuleContext new file mode 100644 index 00000000..0a1dface --- /dev/null +++ b/broker/broker-mongodb/src/main/resources/META-INF/services/dev.usbharu.owl.broker.ModuleContext @@ -0,0 +1 @@ +dev.usbharu.owl.broker.mongodb.MongoModuleContext \ No newline at end of file diff --git a/broker/src/main/kotlin/dev/usbharu/owl/broker/Main.kt b/broker/src/main/kotlin/dev/usbharu/owl/broker/Main.kt index fa01f686..d5184bd1 100644 --- a/broker/src/main/kotlin/dev/usbharu/owl/broker/Main.kt +++ b/broker/src/main/kotlin/dev/usbharu/owl/broker/Main.kt @@ -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 { PropertySerializerFactoryImpl() }