(a) So, you want to get your MBeans populated with your CDI beans?
(b) Or vice-versa?
For (b) CDI Extensions would be the way to go.
Where (a) is a bit trickier.
We arelady failrly experimented with MC beans and CDI.
The code can be found here:
In JMX case, you would somehow need to intercept the MBean usage,
then get CDI' BeanManager, and pass-through this MBean, to get proper @Inject handling.
CDI BeanManager can be found in JNDI, but it needs to be at a proper "time"; e.g. when JNDI context is setup.
Intercepting MBeans would require a bit more work, but can be done.
e.g. use plain MC bean + MC <install>, then register this MC bean as @JMX as well
Thanks for the good suggestions, Ales. From this and suggestions elsewhere it seems that, at present, there isn't a nice, catch-all 'CDI JBoss Service' pattern we should be using.
In the end we went with CDI bean -> JMX - seemed a bit easier, like you say! We created the services as Singleton EJBs, so their injection points are satisfied, which then get registered/unregistered to JMX in their PostConstruct/PreDestroy methods, using German Escobar's excellent CDI portable extension (http://www.germanescobar.net/2010/01/cdi-portable-extension-jmx.html, http://community.jboss.org/thread/148750 is also helpful).
May try to use ApplicationScoped beans and get them to start by observing a ContainerInitialized (or whatever it's called) event, instead, however, as we don't need all the features of a proper EJB. Haven't tried that yet, mind.
Cheers for the help!