How to Inject EPartService

后端 未结 1 497
傲寒
傲寒 2021-01-01 04:08

I am developing e4 application. I want to inject EPartService outside the Part and Handler when i am injecting EPartService then i will get null pointer error



        
相关标签:
1条回答
  • 2021-01-01 04:32

    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.

    0 讨论(0)
提交回复
热议问题