🐛 Register manually created core with event bus
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / main / SoneModule.kt
index 07ec56e..31cc54a 100644 (file)
@@ -16,7 +16,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 +37,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)
@@ -62,10 +61,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)
 
 }