Get an e4 service without injection

I am trying to adapt the Eclipse RCP 3.x application to use some tools with e4. For this reason, there is no e4xmi file.

In particular, I need to access some services:

public class RunModeService {

@Inject
private static ECommandService commandService;
@Inject 
private static EHandlerService handlerService;

...
}

It would seem that if I create a class myself (as I do), then none of the injections takes place.

Is it possible to access these services in another way? If so, I can start connecting to e4 and DI by creating a command whose handler is created by the framework and in which the injection takes place.

+4
source share
2 answers

If you have IEclipseContext, you can get the objects using:

ECommandService commandService = eclipseContext.get(ECommandService.class);

IEclipseContext.

, ContextInjectionFactory, DI :

MyClasss myClass = ContextInjectionFactory.make(MyClass.class, eclipseContext);

:

ContextInjectionFactory.inject(myClass, eclipseContext);

Eclipse view/editor, :

eclipseContext = ((PartSite)getSite()).getContext();

PartSite , .

+3

IEclipseContext:

IEclipseContext context = getActiveEclipseContext();
RunModeService service = ContextInjectionFactory.make(RunModeService.class, context);

IEclipseContext DI, .

0

Source: https://habr.com/ru/post/1542901/