Skip to content

Instantly share code, notes, and snippets.

@Romain-P
Created June 8, 2014 15:07
Show Gist options
  • Save Romain-P/a8497136c99762913cd1 to your computer and use it in GitHub Desktop.
Save Romain-P/a8497136c99762913cd1 to your computer and use it in GitHub Desktop.
like that ;)
package org.heater.test.service;
import com.google.inject.AbstractModule;
import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.Module;
import org.heater.api.HeaterActivator;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import java.util.Hashtable;
public class Activator extends HeaterActivator {
@Inject Injector injector;
@Override
public void start(BundleContext context) throws Exception {
Hashtable<String, String> properties = new Hashtable<>();
properties.put("Plugin", "Test");
TestImpl test = injector.getInstance(TestImpl.class);
context.registerService(TestService.class, test, properties);
}
@Override
public void stop(BundleContext context) throws Exception {
//the context will automatically unregister services
}
@Override
public Module pluginModule() {
return new AbstractModule() {
@Override
protected void configure() {
bind(TestService.class).to(TestImpl.class).asEagerSingleton();
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment