Everyone is beans, BUT
Nothing needs to be done, BUT
(1) bean need to be discovered before can be injected (otherwise leading to WELD-001408: Unsatisfied dependencies)
See
Discovery:
annotate bean with an Bean Defining annotation, so bean can be placed anywhere in an application
Scoped annotations such as @RequestScoped
@Interceptor, @Decorator
All sterotype annotations (maybe just @Stereotype), or
@Dependent scope annotation
change bean discovery mode in bean archive from default "annotated" to "all" by adding beans.xml
and POJO in a standard library (without beans.xml) CANNOT be injected (not discovered)
(2) if bean is declared a passivating scope (in a session), it must be passivation capable (implements Serializable)
Qualifiers
See CDI Qualifier
Producer Methods, Producer Fields, @Disposes
@Produces @QualifierType ReturnType getReturnTypeIeProducer() {...}
producer field - can be private
common use: to generate such as JDBC DataSource or JPA EntityManager and minimize reliance on resource injection
note primitive type (int, etc...), see tutorial example (producer returns "int" and client injects an Instance<Integer>)
@Disposes @QualifierType
public void close(@Disposes @UserDatabase EntityManager em) {em.close()}
Called automatically when the context ends, and the parameter receives the object produced by the producer field
Obtain CDI Managed Bean Instance
http://stackoverflow.com/questions/20048410/canonical-way-to-obtain-cdi-managed-bean-instance-beanmanagergetreference-vs
Uses BeanManager.getReference(), see above reference
Using Alternatives
Choose various versions for different runtime purpose or deployment scenarios (for example, testing)
annotate one or more implementations of the same bean with @Alternative
specify in the beans.xml the one to use <alternatives><class>full.path.to.Class</class></alternatives>
@Priority select beans globally
Using Specialization
another way of alternation... skipped