Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Dependency Injection (Beginner)(Difference between IEclipseContext.set and ContextInjectionFactory.make)
Dependency Injection (Beginner) [message #1295411] Mon, 14 April 2014 08:44 Go to next message
Alexander Klatt is currently offline Alexander Klatt
Messages: 26
Registered: April 2014
Junior Member
Hello,

could anyone please tell me whats the difference between:
IEclipseContext.set and ContextInjectionFactory.make?

Thank you!
Re: Dependency Injection (Beginner) [message #1295591 is a reply to message #1295411] Mon, 14 April 2014 11:56 Go to previous messageGo to next message
Sopot Cela is currently offline Sopot Cela
Messages: 597
Registered: December 2010
Senior Member

CIF#make(Class, Context) creates and returns an instance of class 'Class'. If the class in question requires to be injected with some objects (has an @Inject constructor, field or @Execute method etc.) it uses the context 'Context' to look up (resolve) the objects to inject. Plainly speaking, it creates an object in a given context. That matters because the resolved injection objects can be different in different contexts. CIF#make doesn't put this newly created object in the 'Context' context.

IEC#set(K,V) just sets an *already* created object 'V' to a context with some arbitrary key 'K'. No object creation or injection resolving involved.
Re: Dependency Injection (Beginner) [message #1295603 is a reply to message #1295591] Mon, 14 April 2014 12:06 Go to previous messageGo to next message
Alexander Klatt is currently offline Alexander Klatt
Messages: 26
Registered: April 2014
Junior Member
Okay thank you I think I've got it now!

So the ContextInjectionFactory is just used because a new operator would not support Injection, right?

Re: Dependency Injection (Beginner) [message #1295604 is a reply to message #1295603] Mon, 14 April 2014 12:08 Go to previous messageGo to next message
Sopot Cela is currently offline Sopot Cela
Messages: 597
Registered: December 2010
Senior Member

Right.
Re: Dependency Injection (Beginner) [message #1295634 is a reply to message #1295604] Mon, 14 April 2014 12:44 Go to previous message
Alexander Klatt is currently offline Alexander Klatt
Messages: 26
Registered: April 2014
Junior Member
I've got one more question on my mind..
In the documentation of the CIF I read the following:
"Class'es scope dictates if a new instance of the class will be created, or existing instance will be reused."

Does this mean, that if there is an object already assigned to the variable and i reassign it with CIF,
that I could get different behavior than to assign it to a new variable?

Previous Topic:How can I include custom controls in Application.e4xmi?
Next Topic:tooltip of handled tool item
Goto Forum:
  


Current Time: Thu Oct 02 10:25:47 GMT 2014

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

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