现在使用 @Creatable
注释可以标记要注入(inject)的类,而无需在生命周期中手动将其添加到 EclipseContext
中:
但是,以下情况如何:假设我有一个接口(interface) SomethingService
和一些实现,我想通过以下方式引用其中之一(即注释为可创建的)它的界面,类似于:
@Creatable
class Todo implements SomethingService {
@Inject
public Todo(SomeArg arg) {
// placeholder
}
}
// Field Injection
@Inject private SomethingService service; // Todo instance
这似乎根本行不通。有什么方法可以实现我的需求吗?
最佳答案
好吧,据我所知,我的要求应该使用 OSGi 声明式服务来完成,或者像“Eclipse 4 插件开发示例”中的示例那样修改 Activator:
public class Activator implements BundleActivator {
public void start(BundleContext bundleContext) throws
InjectorFactory.getDefault().
addBinding(IStringService.class).implementedBy(StringService.class);
}
}
谢谢
关于java - 在 E4 应用程序中使用 DI 和 @Creatable 接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23769212/