--- /dev/null
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.freenet.wot;
+
+/**
+ * Custom container for the Web of Trust context. This allows easier
+ * configuration of dependency injection.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class Context {
+
+ private final String context;
+
+ public Context(String context) {
+ this.context = context;
+ }
+
+ public String getContext() {
+ return context;
+ }
+
+}
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
* 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()));
}
//
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;
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;
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);
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 {