I'm trying to integrate kind of 'DI' within my Eclipse 3.x like project.
So I defined some 'business' beans like this:
@Named
class A{...}
@Named class B{ @Inject private A a;
public void doSmtg() { //use a
}
And finally I have an Eclipse AbstractHandler class (registered by a plugin.xml extension point) where i want to Inject the B bean.
public class UIHandler extends AbstractHandler implements IHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
// I want to get my B bean where A is injected
}}
Is it feasible? How can I do this?
Looking at the Sisu Activator, I used the SisuTracker code and now use that snippet to get a bean:
this.resourceToAssetFinder = (ILocator<R, Asset>) Activator.getPlugin().findLocator(Activator.getPlugin().getBundle().getBundleContext()).locate(Key.get(IResourceToAssetLocator.class)).iterator().next().getValue();
This way, all beans are loaded in my bundle's classpath.
Side info, the needed dependencies to bootstrap Sisu are:
<artifact>
<id>com.google.guava:guava:${com.google.guava_guava.version}</id>
</artifact>
<artifact>
<id>com.google.inject:guice:${com.google.inject_guice.version}</id>
<transitive>false</transitive>
</artifact>
<artifact>
<id>com.google.inject.extensions:guice-multibindings:${com.google.inject.extensions_guice-multibindings.version}</id>
<transitive>false</transitive>
</artifact>
<artifact> <id>org.eclipse.sisu:org.eclipse.sisu.inject:${org.eclipse.sisu.version}</id>
</artifact>