Injecting own object to global Eclipse context [message #1618928] |
Mon, 16 February 2015 03:11  |
Eclipse User |
|
|
|
Dear experts,
I am currently injecting my own object to the global Eclipse context, so to make it available through injection anywhere. I am doing this in the plugin activator.
As far as I understand, I can achieve injection of an already created myClass instance (myObj) either by IEclipseContext.set or via CIF:
@Inject
IEclipseContext eclipseContext;
[...]
MyClass myObj = new MyClass(a, b, c, d, e, f, bugsBunny, omega) ;
ContextInjectionFactory.inject(myObj, eclipseContext); // A
eclipseContext.set(MyClass.class, myObj); // B
After this, when application model objects get loaded, I want to exploit DI to get my myObj injected but I cannot get this to work. In both cases I get:
@Inject
MyClass myObj;
||
||
\/
org.eclipse.e4.core.di.InjectionException: Unable to process "Foo.myObj": no actual value was found for the argument "MyClass".
What am I doing wrong?
thanks a lot for your patience,
-Piero
[Updated on: Mon, 16 February 2015 03:41] by Moderator
|
|
|
Re: Injecting own object to global Eclipse context [message #1618934 is a reply to message #1618928] |
Mon, 16 February 2015 03:18   |
Eclipse User |
|
|
|
How do you get access to the context in the Activator? Generally
speaking you can't get access to the correct root context very easily
inside your Activator.
Tom
On 16.02.15 09:11, Piero Campalani wrote:
> Dear experts,
>
> I am currently injecting my own object to the global Eclipse context, so
> to make it available through injection anywhere. I am doing this in the
> plugin activator.
>
> As far as I understand, I can achieve injection of an already created
> myClass instance (myObj) either by IEclipseContext.set or via CIF:
> @Inject
> IEclipseContext eclipseContext;
> [...]
> MyClass myObj = new myClass(a, b, c, d, e, f, bugsBunny, omega) ;
> ContextInjectionFactory.inject(myObj, eclipseContext); // A
> eclipseContext.set(myClass.class, myObj); // B
>
> After this, when application model objects get loaded, I want to exploit
> DI to get my myObj injected but I cannot get this to work. In both cases
> I get:
>
>
> @Inject
> MyClass myObj;
> ||
> ||
> \/
> org.eclipse.e4.core.di.InjectionException: Unable to process
> "Foo.myClass": no actual value was found for the argument "myClass".
>
> What am I doing wrong?
>
> thanks a lot for your patience,
> -Piero
|
|
|
|
|
|
|
|
|
|
Re: Injecting own object to global Eclipse context [message #1622327 is a reply to message #1619228] |
Wed, 18 February 2015 07:17  |
Eclipse User |
|
|
|
Just for the sake of completeness..
I successfully injected my own object in the Eclipse application context by using a context function.
I followed the tutorial by Lars on the matter: link.
As suggested there, if you persist the object in the application context, then the context function will just be called once.
@Lars Vogel: I had to find a separate article (this one) in order to understand a proper location of the component definition (OSGI-INF/) and how to register my component in the plugin MANIFEST (using Service-Component + lazy): you might want to complete the information in your tutorial.
[Updated on: Wed, 18 February 2015 07:42] by Moderator
|
|
|
Powered by
FUDForum. Page generated in 0.25379 seconds