Question

I have a class, which get a MApplication injected. It is a Handler. I want to trigger the Handler's methods manually.

Problem: When I instantiate the Handler manually from another class - the MApplication is null. The class which I trigger the Handler from allready has an MApplication injected, so it is not a lifecycle problem.

Question: How can I trigger a method in a class, which has @Inject annotated methods?

Was it helpful?

Solution

The following made the day.

    ManipulateModelhandler man = new ManipulateModelhandler();

    //inject the context into an object
    //IEclipseContext iEclipseContext was injected into this class
    ContextInjectionFactory.inject(man,iEclipseContext);

    man.execute();

OTHER TIPS

Even shorter:

ContextInjectionFactory.make(ManipulateModelhandler.class, iEclipseContext).execute();

Or by executing the annotated method independent of its name (the way the framework does it):

ContextInjectionFactory.invoke(new ManipulateModelhandler(), Execute.class, iEclipseContext);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top