Use this method
if you want to use dependency injection to separate the creation of
new instances of Java types
from the use of those Java types
in the code. Dependency injection allows for more easily testable
code, while also improving the ability to manage applications.
Implement JAX-RS resources with dependency injection
Java Contexts and
Dependency Injection (JCDI) supports dependency injection in managed
beans. By configuring your web application to be JCDI-enabled, you
can add @javax.inject.Inject annotated fields and
properties. If the annotated fields and properties are valid injection
points with valid JCDI managed beans, then their dependencies will
be resolved during run time. Dependency injection separates the creation
of new instances of Java types
from the use of those Java types
in the code. Dependency injection can allow for more easily testable
code while also improving the ability to manage applications.
Implement JAX-RS resources with different lifecycle scopes
Application developers can use Java Contexts and Dependency Injection (JCDI)
to have different scopes for their managed beans. For instance, if
you have an @javax.enterprise.context.ApplicationScoped annotation
on a Java class named Foo and
multiple @javac.inject.Inject annotated Foo fields
in managed beans, there is only one application-scoped Foo instance
that actually exists.
Implement a JAX-RS resource with decorators and method interceptors
You can use Java Contexts
and Dependency Injection (JCDI) to write interceptors and decorators
for Java API for RESTful Web
Services (JAX-RS) resource types. For example, you can use the interceptor
and decorator capabilities from JCDI to log calls to a particular
class or to complete a security check before invoking a method when
using JCDI-enabled web applications with JAX-RS.