✨ Configure metric registry for injection
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / main / SoneModule.kt
index 07ec56e..8f018f5 100644 (file)
@@ -1,5 +1,6 @@
 package net.pterodactylus.sone.main
 
+import com.codahale.metrics.*
 import com.google.common.base.*
 import com.google.common.eventbus.*
 import com.google.inject.*
@@ -16,7 +17,7 @@ import net.pterodactylus.util.config.ConfigurationException
 import net.pterodactylus.util.version.Version
 import java.io.*
 
-class SoneModule(private val sonePlugin: SonePlugin) : AbstractModule() {
+open class SoneModule(private val sonePlugin: SonePlugin, private val eventBus: EventBus) : AbstractModule() {
 
        override fun configure() {
                val sonePropertiesFile = File("sone.properties")
@@ -37,7 +38,6 @@ class SoneModule(private val sonePlugin: SonePlugin) : AbstractModule() {
                                                        .getValue(null)
                                                        ?.let { DebugLoaders(it) }
                                }
-               val eventBus = EventBus()
 
                bind(Configuration::class.java).toInstance(configuration)
                bind(EventBus::class.java).toInstance(eventBus)
@@ -53,6 +53,7 @@ class SoneModule(private val sonePlugin: SonePlugin) : AbstractModule() {
                bind(Database::class.java).to(MemoryDatabase::class.java).`in`(Singleton::class.java)
                bind(BaseL10n::class.java).toInstance(sonePlugin.l10n().base)
                loaders?.let { bind(Loaders::class.java).toInstance(it) }
+               bind(MetricRegistry::class.java).`in`(Singleton::class.java)
 
                bindListener(Matchers.any(), object : TypeListener {
                        override fun <I> hear(typeLiteral: TypeLiteral<I>, typeEncounter: TypeEncounter<I>) {
@@ -62,10 +63,11 @@ class SoneModule(private val sonePlugin: SonePlugin) : AbstractModule() {
        }
 
        @Provides
+       @Singleton
        fun getCore(configuration: Configuration, freenetInterface: FreenetInterface, identityManager: IdentityManager, soneDownloader: SoneDownloader, imageInserter: ImageInserter, updateChecker: UpdateChecker, webOfTrustUpdater: WebOfTrustUpdater, eventBus: EventBus, database: Database) =
                        Core(configuration, freenetInterface, identityManager, soneDownloader, imageInserter, updateChecker, webOfTrustUpdater, eventBus, database).apply {
                                debugInformation.showVersionInformation = configuration.getBooleanValue("Debug/ShowVersionInformation").getValue(false)
-                       }
+                       }.also(eventBus::register)
 
 }