From fe316906488ff714b5abb64185854ccda714c015 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 16 Jan 2013 22:33:19 +0100 Subject: [PATCH] Automatically register all injected objects with the event bus. --- .../java/net/pterodactylus/sone/main/SonePlugin.java | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) 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 { -- 2.7.4