Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Injection Scope(Which classes are searched in the injection phase)
Injection Scope [message #986409] Tue, 20 November 2012 10:53 Go to next message
Michael Behrisch is currently offline Michael BehrischFriend
Messages: 6
Registered: October 2012
Junior Member
Hello,

I think this could be a stupid question, but I don't find it in the forum:

I have a number of plugins that are injected into the main/core framework.
In each of the plugins the injected class is referenced via the fragment and
its connection to the core's part id. This works all perfectly... But here comes the problem:

Class A is injected into the framework and all @Inject, etc. annotations are resolved.
Whenever class A contains another class B,C,D,.. How do I get them also to be resolved?

E.g. Class B either gets an own context object or the parent context and sets a variable. Now the interested class C does not receive it via the @Named annotation.
Where is my missunderstanding?!?

Maybe to make it more abstract: How do I tell the Eclipse injection mechanism to resolved arbitrary other classes?

Thanks in advance...
Re: Injection Scope [message #986412 is a reply to message #986409] Tue, 20 November 2012 10:58 Go to previous messageGo to next message
Sopot Cela is currently offline Sopot CelaFriend
Messages: 597
Registered: December 2010
Senior Member

1. Each part hast it's own context.
2. If @Inject is not successful in context of part A it goes to the perspective context , if not window context, if not MApplication context (if not OSGi level).
3. If something is in Part A's context its brother part B can not access it but if the thing is in their father's context (window or MApp context) they both can access it. If you want something to be accessible for injection for a certain number of parts put the "something" in a model element (window, perspective or application) common to them.
Re: Injection Scope [message #986417 is a reply to message #986412] Tue, 20 November 2012 11:13 Go to previous messageGo to next message
Michael Behrisch is currently offline Michael BehrischFriend
Messages: 6
Registered: October 2012
Junior Member
Thanks for the fast response, but this is not the problem
The basics that you posted are clear. But the thing is that my problem appears in a single plugin:

The plugin consist of the "entry-point" A in which everything is resolved perfectly.
But if this class contains references to other classes e.g. B and C and B and C should communicate with each other
by means of the context objects or eventbroker service the injection mechanism must get to know B and C.
But I do not understand how I can connect the child contexts (IEclipseContext context = parentPart.getContext(); --> context.createChild())
to the respective class. Thus, if i post something on B, C will not recognize it because it is not automatically injected via
@Named or @UIEventTopic...

Hopefully the problem is now clearer.

PS: Why should I build up something like a Observer Pattern if the injection could do the same thing for me...

[Updated on: Tue, 20 November 2012 11:15]

Report message to a moderator

Re: Injection Scope [message #986441 is a reply to message #986417] Tue, 20 November 2012 12:45 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 386
Registered: December 2010
Location: Germany
Senior Member
Hi Michael

I'm not quite sure what you mean, but maybe you are looking for a pattern like this:
public class A {
	private IEclipseContext myContext;
	private B b;
	
	@PostConstruct
	void init(IEclipseContext context) {
		myContext = context.createChild();
		b = ContextInjectionFactory.make(B.class, myContext);
	}
}

You can now change/put values in myContext. These will be injected into b.

Hope this helps
Christoph
Re: Injection Scope [message #986453 is a reply to message #986441] Tue, 20 November 2012 13:53 Go to previous message
Michael Behrisch is currently offline Michael BehrischFriend
Messages: 6
Registered: October 2012
Junior Member
That is the solution Smile

Thanks Christoph and also thanks to Sopot!
Previous Topic:Where to register central event redistributor?
Next Topic:org.eclipse.ui.PartInitException
Goto Forum:
  


Current Time: Sat Nov 29 01:52:47 GMT 2014

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

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