Sometimes we have a class that has CDI injection point on it but it isn't instantiated by the container, so it is not available for injection to be performed on it. An example of this is a portlet class that needs to inject beans into itself, but a portlet class is instantiated and controlled by a portlet container so Weld is unable to perform injection on it.
In our example, the portlet class would be classified as a non-container managed instance, as the instance of the portlet class is not created by Weld and therefore not managed by it either.
We can ask Weld to perform injection on our portlet class instance as follows:
// get the BeanManager, from JNDI in this example BeanManager beanManager = (BeanManager) new InitialContext().lookup("java:comp/BeanManager"); // create an AnnotatedType for our class AnnotatedType<MyPortlet> portletType = beanManager.createAnnotatedType(myPortlet.getClass()); // create an InjectionTarget InjectionTarget...