Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Injecting a BundleContext
Injecting a BundleContext [message #835963] Tue, 03 April 2012 22:40 Go to next message
Elias Volanakis is currently offline Elias VolanakisFriend
Messages: 26
Registered: July 2009
Junior Member
Hi folks,

does Eclipse 4.2 support having the current BudleContext injected ? Example:

MyClass.java:
@Inject
public void foo(BundleContext context) {
context.doSomething();
}

The above snippet would be nicer than FrameworkUtil.getBundle(MyClass.class).getBundleContext() -- however it does not seem to work.

Thanks for the input,
Elias.


Elias Volanakis | http://eclipsesource.com
elias (AT) eclipsesource.com | @evolanakis
Re: Injecting a BundleContext [message #840782 is a reply to message #835963] Tue, 10 April 2012 13:59 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi,

No there are 2 solutions:
a) you convince Oleg that
1) IContextFunction gets class that requests an injected value
(need to see if I've already filed a bug for it because i wanted
to have this informations in other areas)
2) The DI-Engine knows how to deal with BundleContext magically
itself

b) You make up your own annotation (@BundleContext) and register it
using DS (i have code in my EclipseCon slides [1]) which would make
your code look like this.

MyClass.java:

@Inject
public void foo(@BundleContext BundleContext context) {
context.doSomething();
}

Tom

[1]http://tomsondev.bestsolution.at/2012/03/28/slides-from-eclipsecon-talks/

Am 04.04.12 00:40, schrieb Elias Volanakis:
> Hi folks,
>
> does Eclipse 4.2 support having the current BudleContext injected ?
> Example:
>
> MyClass.java:
> @Inject
> public void foo(BundleContext context) {
> context.doSomething();
> }
>
> The above snippet would be nicer than
> FrameworkUtil.getBundle(MyClass.class).getBundleContext() -- however it
> does not seem to work.
>
> Thanks for the input,
> Elias.
Re: Injecting a BundleContext [message #841278 is a reply to message #840782] Wed, 11 April 2012 05:35 Go to previous message
Erdal Karaca is currently offline Erdal KaracaFriend
Messages: 854
Registered: July 2009
Senior Member
Tom Schindl wrote on Tue, 10 April 2012 09:59

b) You make up your own annotation (@BundleContext) and register it
using DS (i have code in my EclipseCon slides [1]) which would make
your code look like this.

MyClass.java:

@Inject
public void foo(@BundleContext BundleContext context) {
context.doSomething();
}


What about a @Util annotation like this:

Quote:

@Inject
public void foo(@Util BundleContext context) {
context.doSomething();
}


Quote:

@Inject
public void foo(@Util Bundle bundle) {
bundle.doSomething();
}
Previous Topic:Split application model
Next Topic:Interative Tool key in a MacOS ?
Goto Forum:
  


Current Time: Thu Apr 25 09:39:50 GMT 2024

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

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

Back to the top