Skip to main content

Jakarta Contexts and Dependency Injection (Jakarta CDI)

Jakarta Contexts and Dependency Injection (Jakarta CDI) is a Jakarta EE standard that defines a typesafe dependency injection and contextual lifecycle model for Java components in enterprise applications.

  • Typesafe dependency injection model for Java components (application framework)
  • Context and lifecycle management for stateful and stateless components (application runtime)
  • Event-driven communication between loosely coupled components (application integration)
  • Interceptor and decorator support for cross-cutting concerns (application middleware)
  • Integration with other Jakarta EE specifications such as Jakarta Representational State Transfer (REST), Jakarta Persistence, and Jakarta Faces (enterprise application platform)

More About Jakarta Contexts and Dependency Injection

Jakarta Contexts and Dependency Injection (Jakarta CDI) is a core specification in the Jakarta EE platform that defines a unified dependency injection and contextual lifecycle model for managed beans and other components. It provides a programming model that allows developers to declare dependencies, scopes, and interaction patterns using typesafe constructs and annotations, so components can be wired, configured, and managed by the container instead of manual instantiation and lifecycle control.

The specification addresses the problem space of component composition, lifecycle management, and contextual state in enterprise Java applications (application framework). It standardizes how beans are discovered, instantiated, injected, and destroyed, and how they participate in well-defined scopes such as request, session, application, and custom scopes (application runtime). Through qualifiers, producers, and alternatives, CDI enables fine-grained selection of implementations and configuration sources without hard-coded dependencies.

Key capabilities include a dependency injection mechanism that supports constructor, field, and method injection (application framework), a context model that associates beans with scopes that define their lifecycle (application runtime), and an event system for publish-subscribe style interaction between components (application integration). CDI also defines interceptors and decorators for implementing cross-cutting concerns such as logging, security, or transaction-related behavior in a modular way (application middleware). The specification includes rules for bean discovery, resolution, and validation to ensure deterministic wiring of components.

In enterprise environments, Jakarta CDI is used as the foundational programming model for Jakarta EE applications deployed on compliant application servers and runtimes (enterprise application platform). CDI beans integrate with other Jakarta EE technologies such as Jakarta RESTful Web Services for resource classes, Jakarta Persistence for data access components, Jakarta Transactions for transactional behavior, and Jakarta Faces for user interface backing beans. The CDI container coordinates with these technologies so that injection, scopes, and contextual behavior are available across the stack.

From an architectural perspective, Jakarta CDI supports layered and modular application designs in which services, repositories, controllers, and infrastructure components are expressed as beans managed by the container (application architecture). The specification defines a service provider and extension mechanism that allows frameworks and libraries to integrate with CDI and extend its behavior, for example by registering custom scopes, interceptors, or injection points (extensibility framework). This contributes to an ecosystem of CDI-aware libraries within the Jakarta EE environment.

For enterprise technical stakeholders, Jakarta CDI functions as a standard dependency injection and context model that aligns application code with Jakarta EE runtimes, aiding portability across compliant implementations (standards-based development). Its definition as an open specification under the Eclipse Foundation governance model positions it within the broader Jakarta EE set of specifications for building and operating Java-based enterprise systems.