Java 如何在E4应用程序中注入自定义单例bean?

Java 如何在E4应用程序中注入自定义单例bean?,java,dependency-injection,eclipse-rcp,e4,Java,Dependency Injection,Eclipse Rcp,E4,有人能解释一下如何使用Eclipse4DI特性注入我的定制服务/提供者吗 @Singleton public class ConnectionPool { // should be a singleton } public class MyService implements IMyService { @Inject ConnectionPool pool; } // referenced in application model public class SampleP

有人能解释一下如何使用Eclipse4DI特性注入我的定制服务/提供者吗

@Singleton
public class ConnectionPool {
  // should be a singleton
}

public class MyService implements IMyService {
    @Inject
    ConnectionPool pool;
}

// referenced in application model
public class SamplePart {

    @Inject
    IMyService myService;

    @PostConstruct
    public void createComposite(Composite parent) {
       myService.doSomething();
    }
}
或者可以将GoogleGuice(例如)与EclipseDI一起使用吗


我尝试了几个示例(如),但它对我不起作用

您需要将
@createable
注释添加到
ConnectionPool
org.eclipse.e4.core.di.annotations.createable
):

您还可以为该服务使用OSGi服务。也可以在插件或应用程序生命周期类中创建服务。您还可以使用
ContextFunction
创建服务

@Singleton
@Creatable
public class ConnectionPool