🐛 Create Core as singleton
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 12 Jul 2019 05:26:13 +0000 (07:26 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 12 Jul 2019 05:26:13 +0000 (07:26 +0200)
src/main/kotlin/net/pterodactylus/sone/main/SoneModule.kt
src/test/kotlin/net/pterodactylus/sone/main/SoneModuleTest.kt

index 07ec56e..66cd29a 100644 (file)
@@ -62,6 +62,7 @@ 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)
index dd7923d..d928214 100644 (file)
@@ -188,4 +188,11 @@ class SoneModuleTest {
                assertThat(testObject.ref.get(), sameInstance(event))
        }
 
+       @Test
+       fun `core is created as singleton`() {
+               val firstCore = injector.getInstance<Core>()
+               val secondCore = injector.getInstance<Core>()
+               assertThat(secondCore, sameInstance(firstCore))
+       }
+
 }