Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Manually triggering a class with injections?(How to manually trigger a classes method, which uses injections.)
Manually triggering a class with injections? [message #955072] Tue, 23 October 2012 13:38 Go to next message
Alex Kipling is currently offline Alex KiplingFriend
Messages: 257
Registered: July 2012
Senior Member
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?


Re: Manually triggering a class with injections? [message #955081 is a reply to message #955072] Tue, 23 October 2012 13:45 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 386
Registered: December 2010
Location: Germany
Senior Member
Have a look at org.eclipse.e4.core.contexts.ContextInjectionFactory
Re: Manually triggering a class with injections? [message #955109 is a reply to message #955081] Tue, 23 October 2012 14:18 Go to previous messageGo to next message
Alex Kipling is currently offline Alex KiplingFriend
Messages: 257
Registered: July 2012
Senior Member
Thnx, the following Injected everything from the current iEclipseContext into the new Object.

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

Re: Manually triggering a class with injections? [message #955571 is a reply to message #955109] Tue, 23 October 2012 22:30 Go to previous messageGo to next message
jim liu is currently offline jim liuFriend
Messages: 37
Registered: February 2011
Location: shanghai
Member
I think you should invoke ContextInjectFactory.invoke method with @Execute as parameter

java eclipse Search
http://javafind.appspot.com/
Re: Manually triggering a class with injections? [message #960843 is a reply to message #955072] Sat, 27 October 2012 21:28 Go to previous message
Sopot Cela is currently offline Sopot CelaFriend
Messages: 597
Registered: December 2010
Senior Member

Even though I'm not aware of what you are trying to achieve, creating handlers manually and calling @inject methods with CIF does not sound the right approach except in some really advanced cases IMHO.

Anyway, getting to your question the CIF.invoke will invoke annotated methods for you.
Previous Topic:Logger-Layout?
Next Topic:Does e4 support opening a view in a dialog shell?!
Goto Forum:
  


Current Time: Fri Nov 28 16:13:24 GMT 2014

Powered by FUDForum. Page generated in 0.03063 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software