I use weld+paxcdi on java se. I can get the reference to beanManager using
@Inject
BeanManager beanManager;
However, it's clear that I can use this way only in objects that are managed by CDI container. How can I get reference to beanmanager in object that was created by new?
I assume the question refers to OSGi, as it wouldn't make sense to use Pax CDI otherwise.
Pax CDI creates a separate CDI container and thus a separate bean manager per bean bundle. For this reason, it is not quite obvious what the current bean manager should be.
As of Pax CDI 1.0.0.RC1, CDI.current()
returns a meaningful value when called from an OsgiServiceProvider
method, if the method target is an injection point in the calling class. CDI.current()
is undefined otherwise.
Pax CDI 0.x is based on CDI 1.0 and thus does not support CDI.current()
.