ops4j / peaberry

42 stars 9 forks source link

PeaberryActivationModule should provide a reference to OSGi BundleContext #56

Open mcculls opened 9 years ago

mcculls commented 9 years ago

Originally reported on Google Code with ID 53

If the user uses the automatic bootstrapping of Peaberry bundles, there is NO way to
get the BundleContext object.

Reported by yungkce on 2010-10-13 11:24:00

mcculls commented 9 years ago
As Todor mentioned on the mailing list, just @Inject BundleContext wherever you need
it.

Reported by mcculls on 2010-10-13 18:00:03

mcculls commented 9 years ago
But what if I would like to refer to the BundleContext in the PeaberryActivationModule's
configure() method? It is before Guice @Inject the BundleContext object.

Reported by yungkce on 2010-10-14 07:42:26

mcculls commented 9 years ago
Can you elaborate on what you need to use the BundleContext for in the module itself?
Binding modules are usually small and side-effect free, so I'm just wondering why you
need the context when setting up bindings.

Reported by mcculls on 2010-10-14 10:48:22

mcculls commented 9 years ago
Since I would like to use the Manifest header of the bundle for setting the attributes
of the exported services inside the configure() method, the only way to get those header
is from the BundleContext.getBundle().getHeaders() method unless I can export the services
outside the configure() method.

Reported by yungkce on 2010-11-12 10:53:02

mcculls commented 9 years ago
It seems best to pass the BundleContext to the module constructor. Currently we expect
the module to have a default constructor. We could support a constructor with a BundleContext
as well. I am not sure how nice this will be since now there are two ways to obtain
the BundleContext and the users cat try to bind it a second time.

Stuart what do you think?

Reported by Rinsvind on 2010-11-12 13:48:48

mcculls commented 9 years ago

Reported by mcculls on 2012-08-04 21:41:37