I'm facing the following situation: I have written a CDI extension, with which I want to programatically register additional beans into the BeanManager
. I've already implemented the extension and registered in in the META-INF/services
folder. Everything works fine so far and I can trace the container calling this method:
public class TestCdiExtension implements Extension {
public void observeAfterBeanDiscovery(@Observes AfterBeanDiscovery event, BeanManager manager) {
// Code goes here
}
}
My problem now is this: To determine which beans should be registered, I need access to the ServletContext
of the current web application in which CDI is running.
I understand that you can use CDI completely without a servlet environm开发者_如何转开发ent, so there is no hard link. However: How can I do the job of registering additional beans depending on what's in the ServletContext
?
Is using an extension the correct way at all? Is there any other (better?) solution of doing this?
精彩评论