From: David ‘Bombe’ Roden Date: Wed, 16 Jan 2013 21:33:19 +0000 (+0100) Subject: Automatically register all injected objects with the event bus. X-Git-Tag: 0.8.5^2~3^2~93 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=fe316906488ff714b5abb64185854ccda714c015;p=Sone.git Automatically register all injected objects with the event bus. --- diff --git a/src/main/java/net/pterodactylus/sone/main/SonePlugin.java b/src/main/java/net/pterodactylus/sone/main/SonePlugin.java index 32adff9..bed9397 100644 --- a/src/main/java/net/pterodactylus/sone/main/SonePlugin.java +++ b/src/main/java/net/pterodactylus/sone/main/SonePlugin.java @@ -43,7 +43,12 @@ import com.google.inject.AbstractModule; import com.google.inject.Guice; import com.google.inject.Injector; import com.google.inject.Singleton; +import com.google.inject.TypeLiteral; +import com.google.inject.matcher.Matchers; import com.google.inject.name.Names; +import com.google.inject.spi.InjectionListener; +import com.google.inject.spi.TypeEncounter; +import com.google.inject.spi.TypeListener; import freenet.client.async.DatabaseDisabledException; import freenet.l10n.BaseL10n.LANGUAGE; @@ -212,7 +217,21 @@ public class SonePlugin implements FredPlugin, FredPluginFCP, FredPluginL10n, Fr bind(String.class).annotatedWith(Names.named("WebOfTrustContext")).toInstance("Sone"); bind(SonePlugin.class).toInstance(SonePlugin.this); bind(FcpInterface.class).in(Singleton.class); + bindListener(Matchers.any(), new TypeListener() { + + @Override + public void hear(TypeLiteral typeLiteral, TypeEncounter typeEncounter) { + typeEncounter.register(new InjectionListener() { + + @Override + public void afterInjection(I injectee) { + eventBus.register(injectee); + } + }); + } + }); } + }; Injector injector = Guice.createInjector(freenetModule, soneModule); core = injector.getInstance(Core.class); @@ -226,7 +245,6 @@ public class SonePlugin implements FredPlugin, FredPluginFCP, FredPluginL10n, Fr /* create the web interface. */ webInterface = injector.getInstance(WebInterface.class); - eventBus.register(webInterface); boolean startupFailed = true; try {