From: David ‘Bombe’ Roden Date: Fri, 27 Jun 2014 16:00:33 +0000 (+0200) Subject: Add custom context type for dependency injection. X-Git-Tag: 0.9-rc1^2~3^2~223 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=88469a40e677180866ae22f991dd547d0a367522;p=Sone.git Add custom context type for dependency injection. --- diff --git a/src/main/java/net/pterodactylus/sone/freenet/wot/Context.java b/src/main/java/net/pterodactylus/sone/freenet/wot/Context.java new file mode 100644 index 0000000..0f730fa --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/freenet/wot/Context.java @@ -0,0 +1,38 @@ +/* + * Sone - Context.java - Copyright © 2014 David Roden + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.sone.freenet.wot; + +/** + * Custom container for the Web of Trust context. This allows easier + * configuration of dependency injection. + * + * @author David ‘Bombe’ Roden + */ +public class Context { + + private final String context; + + public Context(String context) { + this.context = context; + } + + public String getContext() { + return context; + } + +} diff --git a/src/main/java/net/pterodactylus/sone/freenet/wot/IdentityManager.java b/src/main/java/net/pterodactylus/sone/freenet/wot/IdentityManager.java index e89c667..810e054 100644 --- a/src/main/java/net/pterodactylus/sone/freenet/wot/IdentityManager.java +++ b/src/main/java/net/pterodactylus/sone/freenet/wot/IdentityManager.java @@ -33,7 +33,6 @@ import com.google.common.collect.Multimap; import com.google.common.collect.Sets; import com.google.common.eventbus.EventBus; import com.google.inject.Inject; -import com.google.inject.name.Named; /** * The identity manager takes care of loading and storing identities, their @@ -74,11 +73,11 @@ public class IdentityManager extends AbstractService { * contexts) */ @Inject - public IdentityManager(EventBus eventBus, WebOfTrustConnector webOfTrustConnector, @Named("WebOfTrustContext") String context) { + public IdentityManager(EventBus eventBus, WebOfTrustConnector webOfTrustConnector, Context context) { super("Sone Identity Manager", false); this.eventBus = eventBus; this.webOfTrustConnector = webOfTrustConnector; - this.identityLoader = new IdentityLoader(webOfTrustConnector, fromNullable(context)); + this.identityLoader = new IdentityLoader(webOfTrustConnector, fromNullable(context.getContext())); } // diff --git a/src/main/java/net/pterodactylus/sone/main/SonePlugin.java b/src/main/java/net/pterodactylus/sone/main/SonePlugin.java index 9d31b35..5b27282 100644 --- a/src/main/java/net/pterodactylus/sone/main/SonePlugin.java +++ b/src/main/java/net/pterodactylus/sone/main/SonePlugin.java @@ -34,6 +34,7 @@ import net.pterodactylus.sone.database.memory.MemoryDatabase; import net.pterodactylus.sone.fcp.FcpInterface; import net.pterodactylus.sone.freenet.PluginStoreConfigurationBackend; import net.pterodactylus.sone.freenet.plugin.PluginConnector; +import net.pterodactylus.sone.freenet.wot.Context; import net.pterodactylus.sone.freenet.wot.IdentityManager; import net.pterodactylus.sone.freenet.wot.WebOfTrustConnector; import net.pterodactylus.sone.web.WebInterface; @@ -51,7 +52,6 @@ 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; @@ -225,10 +225,10 @@ public class SonePlugin implements FredPlugin, FredPluginFCP, FredPluginL10n, Fr bind(Configuration.class).toInstance(startConfiguration); bind(FreenetInterface.class).in(Singleton.class); bind(PluginConnector.class).in(Singleton.class); + bind(Context.class).toInstance(new Context("Sone")); bind(WebOfTrustConnector.class).in(Singleton.class); bind(WebOfTrustUpdater.class).in(Singleton.class); bind(IdentityManager.class).in(Singleton.class); - bind(String.class).annotatedWith(Names.named("WebOfTrustContext")).toInstance("Sone"); bind(SonePlugin.class).toInstance(SonePlugin.this); bind(FcpInterface.class).in(Singleton.class); bind(Database.class).to(MemoryDatabase.class); diff --git a/src/test/java/net/pterodactylus/sone/freenet/wot/IdentityManagerTest.java b/src/test/java/net/pterodactylus/sone/freenet/wot/IdentityManagerTest.java index 321f55c..2bb6d1f 100644 --- a/src/test/java/net/pterodactylus/sone/freenet/wot/IdentityManagerTest.java +++ b/src/test/java/net/pterodactylus/sone/freenet/wot/IdentityManagerTest.java @@ -20,7 +20,7 @@ public class IdentityManagerTest { private final EventBus eventBus = mock(EventBus.class); private final WebOfTrustConnector webOfTrustConnector = mock(WebOfTrustConnector.class); - private final IdentityManager identityManager = new IdentityManager(eventBus, webOfTrustConnector, "Test"); + private final IdentityManager identityManager = new IdentityManager(eventBus, webOfTrustConnector, new Context("Test")); @Test public void identityManagerPingsWotConnector() throws PluginException {