How to Inject EPartService

限于喜欢 提交于 2019-11-30 10:15:50

Eclipse only does direct injection on objects that it 'knows' about - basically objects mentioned in the application model (e4xmi) files or created using something like EPartService.showPart.

If you want to do direct injection on objects that you create then you need to create them using ContextInjectionFactory. For example:

@Inject IEclipseContext context;

...

MyClass myClass = ContextInjectionFactory.make(MyClass.class, context);

you can also do injection on a class created in the normal way with:

ContextInjectionFactory.inject(myClass, context);

(this will not do injection on the constructor).

Note: Since this code is using direct injection you must run it from a class that the Eclipse application model does know about such as a command handler or an MPart.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!