如何从使用new()实例化的实例中检索Eclipse Sisu创建的bean



我正在尝试在Eclipse 3中集成一种'DI'。X like project.

所以我像这样定义了一些"业务"bean:

@Named
class A{...}
@Named class B{ @Inject private A a;
public void doSmtg() { //use a
}

最后我有一个Eclipse AbstractHandler类(由plugin.xml扩展点注册),我想在其中注入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
}}

可行吗?我该怎么做呢?

查看Sisu Activator,我使用了SisuTracker代码,现在使用该代码片段获取bean:

this.resourceToAssetFinder = (ILocator<R, Asset>) Activator.getPlugin().findLocator(Activator.getPlugin().getBundle().getBundleContext()).locate(Key.get(IResourceToAssetLocator.class)).iterator().next().getValue();

这样,所有的bean都被加载到包的类路径中。

侧信息,启动Sisu所需的依赖项如下:

 <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>

最新更新