<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.10.0">Jekyll</generator><link href="https://jakartaee.github.io/cdi/feed.xml" rel="self" type="application/atom+xml" /><link href="https://jakartaee.github.io/cdi/" rel="alternate" type="text/html" /><updated>2026-11-13T15:22:08+00:00</updated><id>https://jakartaee.github.io/cdi/feed.xml</id><title type="html">Jakarta CDI</title><subtitle>This is the site for the Jakarta Contexts and Dependency Injection API and Specification project.</subtitle><entry><title type="html">What’s new in CDI 5.0?</title><link href="https://jakartaee.github.io/cdi/2026/06/05/whats-new-in-cdi50.html" rel="alternate" type="text/html" title="What’s new in CDI 5.0?" /><published>2026-06-05T00:00:00+00:00</published><updated>2026-06-05T00:00:00+00:00</updated><id>https://jakartaee.github.io/cdi/2026/06/05/whats-new-in-cdi50</id><content type="html" xml:base="https://jakartaee.github.io/cdi/2026/06/05/whats-new-in-cdi50.html"><![CDATA[<p>It’s been a busy time in the CDI world.
CDI 5.0 is on its way, bringing several long-requested additions along with it.
This release also raises the minimum Java version to 17.
In this post, we’ll go through the most important changes — starting with one that requires your attention even if you don’t plan to use any of the new features.</p>

<h2 id="maven-coordinate-changes">Maven Coordinate Changes</h2>

<p>Before diving into the new features, let’s cover an important housekeeping matter.
The Maven coordinates (GAV) of all CDI API artifacts have changed in CDI 5.0 — both the <code class="language-plaintext highlighter-rouge">groupId</code> and <code class="language-plaintext highlighter-rouge">artifactId</code>:</p>

<table>
  <thead>
    <tr>
      <th>Old (CDI 4.x)</th>
      <th>New (CDI 5.0)</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">jakarta.enterprise:jakarta.enterprise.cdi-api</code></td>
      <td><code class="language-plaintext highlighter-rouge">jakarta.cdi:jakarta.cdi-api</code></td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">jakarta.enterprise:jakarta.enterprise.cdi-el-api</code></td>
      <td><code class="language-plaintext highlighter-rouge">jakarta.cdi:jakarta.cdi-el-api</code></td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">jakarta.enterprise:jakarta.enterprise.lang-model</code></td>
      <td><code class="language-plaintext highlighter-rouge">jakarta.cdi:jakarta.cdi-lang-model-api</code></td>
    </tr>
  </tbody>
</table>

<p>Relocation artifacts are published under the old coordinates, so Maven and Gradle will resolve them automatically for now.
However, relocation artifacts will only be present for the 5.0 release — they will not be carried over to future versions.
Please update your POM files or build scripts as soon as possible.</p>

<p>The CDI TCK artifacts have undergone a similar coordinate change but do not provide relocation artifacts.</p>

<h2 id="eager-initialization">Eager Initialization</h2>

<p><code class="language-plaintext highlighter-rouge">@ApplicationScoped</code> beans are normally created lazily — the container only instantiates them when they are first accessed.
Sometimes, however, you want a bean to be ready as soon as the application starts.</p>

<p>A common pattern for this was to declare a <code class="language-plaintext highlighter-rouge">Startup</code> event observer, but that is more ceremony than needed when the bean’s constructor or <code class="language-plaintext highlighter-rouge">@PostConstruct</code> already does everything.
CDI 5.0 adds <code class="language-plaintext highlighter-rouge">@Eager</code> as a dedicated annotation for this case.
<code class="language-plaintext highlighter-rouge">Startup</code> event observers remain valuable when you need to execute more complex initialization logic.</p>

<div class="language-java highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nd">@ApplicationScoped</span>
<span class="nd">@Eager</span>
<span class="kd">public</span> <span class="kd">class</span> <span class="nc">StartupService</span> <span class="o">{</span>

    <span class="nd">@PostConstruct</span>
    <span class="kd">public</span> <span class="kt">void</span> <span class="nf">init</span><span class="o">()</span> <span class="o">{</span>
        <span class="c1">// executed during application startup,</span>
        <span class="c1">// no need to inject this bean anywhere</span>
    <span class="o">}</span>
<span class="o">}</span>
</code></pre></div></div>

<p>An eagerly initialized bean is instantiated no later than when the container fires the <code class="language-plaintext highlighter-rouge">Startup</code> event.
It also works on producer methods:</p>

<div class="language-java highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nd">@ApplicationScoped</span>
<span class="kd">public</span> <span class="kd">class</span> <span class="nc">ServiceProducer</span> <span class="o">{</span>

    <span class="nd">@Produces</span>
    <span class="nd">@ApplicationScoped</span>
    <span class="nd">@Eager</span>
    <span class="kd">public</span> <span class="nc">CacheService</span> <span class="nf">createCache</span><span class="o">()</span> <span class="o">{</span>
        <span class="k">return</span> <span class="k">new</span> <span class="nf">CacheService</span><span class="o">();</span>
    <span class="o">}</span>
<span class="o">}</span>
</code></pre></div></div>

<p><code class="language-plaintext highlighter-rouge">@Eager</code> can also be placed on a stereotype.
Note that only <code class="language-plaintext highlighter-rouge">@ApplicationScoped</code> beans may be eagerly initialized — using <code class="language-plaintext highlighter-rouge">@Eager</code> on a <code class="language-plaintext highlighter-rouge">@RequestScoped</code> or <code class="language-plaintext highlighter-rouge">@Dependent</code> bean is a definition error.
That said, <code class="language-plaintext highlighter-rouge">@Singleton</code> beans are likely to be supported by major implementations as well.</p>

<h2 id="reserve-beans">Reserve Beans</h2>

<p>CDI has long had <code class="language-plaintext highlighter-rouge">@Alternative</code> as a way to provide a “more important” implementation of a bean.
However, this is quite cumbersome in one common use case: providing a default implementation that should be used only when no other bean is available.</p>

<p>CDI 5.0 introduces <code class="language-plaintext highlighter-rouge">@Reserve</code> for exactly this purpose: to provide a “less important” implementation of a bean.
A reserve bean only participates in typesafe resolution when no other non-reserve bean matches.
Consider the following example:</p>

<div class="language-java highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">public</span> <span class="kd">interface</span> <span class="nc">Greeter</span> <span class="o">{</span>
    <span class="nc">String</span> <span class="nf">greet</span><span class="o">(</span><span class="nc">String</span> <span class="n">name</span><span class="o">);</span>
<span class="o">}</span>
</code></pre></div></div>

<div class="language-java highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nd">@Dependent</span>
<span class="nd">@Reserve</span>
<span class="nd">@Priority</span><span class="o">(</span><span class="mi">1</span><span class="o">)</span>
<span class="kd">public</span> <span class="kd">class</span> <span class="nc">DefaultGreeter</span> <span class="kd">implements</span> <span class="nc">Greeter</span> <span class="o">{</span>

    <span class="kd">public</span> <span class="nc">String</span> <span class="nf">greet</span><span class="o">(</span><span class="nc">String</span> <span class="n">name</span><span class="o">)</span> <span class="o">{</span>
        <span class="k">return</span> <span class="s">"Hello "</span> <span class="o">+</span> <span class="n">name</span> <span class="o">+</span> <span class="s">"!"</span><span class="o">;</span>
    <span class="o">}</span>
<span class="o">}</span>
</code></pre></div></div>

<div class="language-java highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nd">@Dependent</span>
<span class="kd">public</span> <span class="kd">class</span> <span class="nc">CustomGreeter</span> <span class="kd">implements</span> <span class="nc">Greeter</span> <span class="o">{</span>

    <span class="kd">public</span> <span class="nc">String</span> <span class="nf">greet</span><span class="o">(</span><span class="nc">String</span> <span class="n">name</span><span class="o">)</span> <span class="o">{</span>
        <span class="k">return</span> <span class="s">"Hi "</span> <span class="o">+</span> <span class="n">name</span> <span class="o">+</span> <span class="s">", welcome back!"</span><span class="o">;</span>
    <span class="o">}</span>
<span class="o">}</span>
</code></pre></div></div>

<p>When <code class="language-plaintext highlighter-rouge">CustomGreeter</code> is present, it wins — it’s a regular bean and takes precedence over any reserve.
If it were removed, <code class="language-plaintext highlighter-rouge">DefaultGreeter</code> would kick in as the fallback.
When multiple reserves are available, <code class="language-plaintext highlighter-rouge">@Priority</code> determines which one is selected.</p>

<p>Note that <code class="language-plaintext highlighter-rouge">@Alternative</code> and <code class="language-plaintext highlighter-rouge">@Reserve</code> are mutually exclusive — combining them on the same bean is a definition error.</p>

<h2 id="automatic-resource-cleanup">Automatic Resource Cleanup</h2>

<p>Beans that manage external resources often implement <code class="language-plaintext highlighter-rouge">AutoCloseable</code>.
Until now, you had to write a <code class="language-plaintext highlighter-rouge">@PreDestroy</code> method that delegated to <code class="language-plaintext highlighter-rouge">close()</code> — a small but repetitive boilerplate.</p>

<p>CDI 5.0 adds the <code class="language-plaintext highlighter-rouge">@AutoClose</code> annotation.
When a bean is annotated <code class="language-plaintext highlighter-rouge">@AutoClose</code> and implements <code class="language-plaintext highlighter-rouge">AutoCloseable</code>, the container automatically calls <code class="language-plaintext highlighter-rouge">close()</code> when the bean is destroyed:</p>

<div class="language-java highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nd">@Dependent</span>
<span class="nd">@AutoClose</span>
<span class="kd">public</span> <span class="kd">class</span> <span class="nc">ManagedConnection</span> <span class="kd">implements</span> <span class="nc">AutoCloseable</span> <span class="o">{</span>

    <span class="kd">public</span> <span class="nf">ManagedConnection</span><span class="o">()</span> <span class="o">{</span>
        <span class="c1">// open connection</span>
    <span class="o">}</span>

    <span class="nd">@Override</span>
    <span class="kd">public</span> <span class="kt">void</span> <span class="nf">close</span><span class="o">()</span> <span class="kd">throws</span> <span class="nc">Exception</span> <span class="o">{</span>
        <span class="c1">// connection is closed automatically</span>
        <span class="c1">// when the bean is destroyed</span>
    <span class="o">}</span>
<span class="o">}</span>
</code></pre></div></div>

<p>If the bean also has a <code class="language-plaintext highlighter-rouge">@PreDestroy</code> method, it is called first, and <code class="language-plaintext highlighter-rouge">close()</code> is called afterwards.
The behavior is opt-in — if a bean implements <code class="language-plaintext highlighter-rouge">AutoCloseable</code> but is not annotated <code class="language-plaintext highlighter-rouge">@AutoClose</code>, the container does not call <code class="language-plaintext highlighter-rouge">close()</code>.</p>

<h2 id="synthetic-bean-injection-points">Synthetic Bean Injection Points</h2>

<p>Build Compatible Extensions can create <em>synthetic beans</em> — beans that don’t correspond to a class in the application, but are defined programmatically by an extension.
Until CDI 5.0, the creation function of a synthetic bean received an <code class="language-plaintext highlighter-rouge">Instance&lt;Object&gt;</code> through which it could resolve any bean in the container dynamically.</p>

<p>CDI 5.0 introduces a more explicit approach.
Extensions can now declare the exact injection points of a synthetic bean using <code class="language-plaintext highlighter-rouge">withInjectionPoint()</code>.
The creation function then receives a <code class="language-plaintext highlighter-rouge">SyntheticInjections</code> object to look up those specific dependencies:</p>

<div class="language-java highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">public</span> <span class="kd">class</span> <span class="nc">MyExtension</span> <span class="kd">implements</span> <span class="nc">BuildCompatibleExtension</span> <span class="o">{</span>

    <span class="nd">@Synthesis</span>
    <span class="kd">public</span> <span class="kt">void</span> <span class="nf">register</span><span class="o">(</span><span class="nc">SyntheticComponents</span> <span class="n">syn</span><span class="o">)</span> <span class="o">{</span>
        <span class="n">syn</span><span class="o">.</span><span class="na">addBean</span><span class="o">(</span><span class="nc">MyPojo</span><span class="o">.</span><span class="na">class</span><span class="o">)</span>
                <span class="o">.</span><span class="na">type</span><span class="o">(</span><span class="nc">MyPojo</span><span class="o">.</span><span class="na">class</span><span class="o">)</span>
                <span class="o">.</span><span class="na">scope</span><span class="o">(</span><span class="nc">Dependent</span><span class="o">.</span><span class="na">class</span><span class="o">)</span>
                <span class="o">.</span><span class="na">withInjectionPoint</span><span class="o">(</span><span class="nc">MyService</span><span class="o">.</span><span class="na">class</span><span class="o">)</span>
                <span class="o">.</span><span class="na">createWith</span><span class="o">(</span><span class="nc">MyPojoCreator</span><span class="o">.</span><span class="na">class</span><span class="o">);</span>
    <span class="o">}</span>
<span class="o">}</span>
</code></pre></div></div>

<div class="language-java highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">public</span> <span class="kd">class</span> <span class="nc">MyPojoCreator</span> <span class="kd">implements</span> <span class="nc">SyntheticBeanCreator</span><span class="o">&lt;</span><span class="nc">MyPojo</span><span class="o">&gt;</span> <span class="o">{</span>

    <span class="nd">@Override</span>
    <span class="kd">public</span> <span class="nc">MyPojo</span> <span class="nf">create</span><span class="o">(</span><span class="nc">SyntheticInjections</span> <span class="n">injections</span><span class="o">,</span> <span class="nc">Parameters</span> <span class="n">params</span><span class="o">)</span> <span class="o">{</span>
        <span class="nc">MyService</span> <span class="n">service</span> <span class="o">=</span> <span class="n">injections</span><span class="o">.</span><span class="na">get</span><span class="o">(</span><span class="nc">MyService</span><span class="o">.</span><span class="na">class</span><span class="o">);</span>
        <span class="k">return</span> <span class="k">new</span> <span class="nf">MyPojo</span><span class="o">(</span><span class="n">service</span><span class="o">);</span>
    <span class="o">}</span>
<span class="o">}</span>
</code></pre></div></div>

<p>Because the dependencies are declared up front, the container can validate injection points at deployment time and perform optimizations in build-time environments.
The old <code class="language-plaintext highlighter-rouge">SyntheticBeanCreator.create(Instance&lt;Object&gt;, Parameters)</code> method is deprecated for removal.</p>

<h2 id="further-additions">Further Additions</h2>

<p>There are several more additions in CDI 5.0 that are worth noting:</p>

<ul>
  <li>Asynchronous invokers — the <code class="language-plaintext highlighter-rouge">AsyncHandler</code> SPI allows framework authors to handle async method invocations through method invokers, with built-in support for <code class="language-plaintext highlighter-rouge">CompletionStage</code>, <code class="language-plaintext highlighter-rouge">CompletableFuture</code>, and <code class="language-plaintext highlighter-rouge">Flow.Publisher</code>.</li>
  <li>Introduction of the <em>global scope</em> concept — a global scope has exactly one context object, active on all threads for the entire lifetime of the container. <code class="language-plaintext highlighter-rouge">@ApplicationScoped</code> and <code class="language-plaintext highlighter-rouge">@Dependent</code> are global scopes; <code class="language-plaintext highlighter-rouge">@Singleton</code> is likely to be treated as global by major implementations as well.</li>
  <li>Programmatic registration of <code class="language-plaintext highlighter-rouge">BuildCompatibleExtension</code> in CDI SE via <code class="language-plaintext highlighter-rouge">SeContainerInitializer</code>.</li>
  <li><code class="language-plaintext highlighter-rouge">@Registration</code> now allows parameterized types.</li>
  <li><code class="language-plaintext highlighter-rouge">InjectionPoint</code> behavior is now defined for beans obtained via <code class="language-plaintext highlighter-rouge">CDI.current()</code> (previously unspecified and implementation-dependent).</li>
</ul>

<h2 id="removals-and-breaking-changes">Removals and Breaking Changes</h2>

<ul>
  <li><code class="language-plaintext highlighter-rouge">SecurityManager</code> usage and references have been removed.</li>
  <li>Deprecated <code class="language-plaintext highlighter-rouge">BeanManager</code> EL methods have been removed (replaced by <code class="language-plaintext highlighter-rouge">ELAwareBeanManager</code> since CDI 4.1).</li>
  <li>Trimming is now forbidden in non-explicit bean archives.</li>
  <li>Minimum Java version raised to 17.</li>
</ul>

<h2 id="conclusion">Conclusion</h2>

<p>CDI 5.0 is a significant release with features useful for both application developers and framework authors.
If you have any questions, suggestions, or ideas, feel free to reach out on the <code class="language-plaintext highlighter-rouge">cdi-dev@eclipse.org</code> mailing list or open an issue on the <a href="https://github.com/jakartaee/cdi/issues">CDI GitHub repository</a>.</p>]]></content><author><name>matn</name></author><category term="development-tips" /><summary type="html"><![CDATA[It’s been a busy time in the CDI world. CDI 5.0 is on its way, bringing several long-requested additions along with it. This release also raises the minimum Java version to 17. In this post, we’ll go through the most important changes — starting with one that requires your attention even if you don’t plan to use any of the new features.]]></summary></entry><entry><title type="html">What’s new in CDI 4.1?</title><link href="https://jakartaee.github.io/cdi/2024/02/27/whats-new-in-cdi41.html" rel="alternate" type="text/html" title="What’s new in CDI 4.1?" /><published>2024-02-27T00:00:00+00:00</published><updated>2024-02-27T00:00:00+00:00</updated><id>https://jakartaee.github.io/cdi/2024/02/27/whats-new-in-cdi41</id><content type="html" xml:base="https://jakartaee.github.io/cdi/2024/02/27/whats-new-in-cdi41.html"><![CDATA[<p>If you’re following the activity on the <a href="https://github.com/jakartaee/cdi/">CDI repository</a>, or in Jakarta EE in general, you might have noticed that the CDI 4.1 release is coming soon.
In this short post, we’ll take a look at what’s new in the wonderful world of CDI.</p>

<h2 id="method-invokers">Method Invokers</h2>

<p>The most important (or at least the biggest) addition to CDI is <em>method invokers</em>.
It is not terribly interesting for application developers, but it should be very useful for people who build CDI-based frameworks.</p>

<p>A method invoker is, unsurprisingly, an object that allows invoking a method indirectly.
It implements the <code class="language-plaintext highlighter-rouge">jakarta.enterprise.invoke.Invoker</code> interface, which is very simple:</p>

<div class="language-java highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">interface</span> <span class="nc">Invoker</span><span class="o">&lt;</span><span class="no">T</span><span class="o">,</span> <span class="no">R</span><span class="o">&gt;</span> <span class="o">{</span>
    <span class="no">R</span> <span class="nf">invoke</span><span class="o">(</span><span class="no">T</span> <span class="n">instance</span><span class="o">,</span> <span class="nc">Object</span><span class="o">[]</span> <span class="n">arguments</span><span class="o">)</span> <span class="kd">throws</span> <span class="nc">Exception</span><span class="o">;</span>
<span class="o">}</span>
</code></pre></div></div>

<p>CDI extensions can create an invoker for methods (including <code class="language-plaintext highlighter-rouge">static</code> methods) declared on managed beans.
For example, let’s say the application contains this bean:</p>

<div class="language-java highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nd">@Dependent</span>
<span class="kd">public</span> <span class="kd">class</span> <span class="nc">MyService</span> <span class="o">{</span>
    <span class="kd">public</span> <span class="nc">String</span> <span class="nf">hello</span><span class="o">(</span><span class="nc">String</span> <span class="n">name</span><span class="o">)</span> <span class="o">{</span>
        <span class="k">return</span> <span class="s">"Hello "</span> <span class="o">+</span> <span class="n">name</span> <span class="o">+</span> <span class="s">"!"</span><span class="o">;</span>
    <span class="o">}</span>
<span class="o">}</span>
</code></pre></div></div>

<p>A hypothetical CDI-based framework can decide that it might need to invoke the method at runtime.
During deployment, the CDI extension provided by the framework would use</p>

<ul>
  <li><code class="language-plaintext highlighter-rouge">ProcessManagedBean.createInvoker()</code>, if using a Portable Extension</li>
  <li><code class="language-plaintext highlighter-rouge">InvokerFactory.createInvoker()</code>, if using a Build Compatible Extension</li>
</ul>

<p>to obtain an <code class="language-plaintext highlighter-rouge">InvokerBuilder</code>. Calling <code class="language-plaintext highlighter-rouge">build()</code> on it will produce</p>

<ul>
  <li>an <code class="language-plaintext highlighter-rouge">Invoker</code> directly, if using a Portable Extension</li>
  <li>an <code class="language-plaintext highlighter-rouge">InvokerInfo</code> that materializes as an <code class="language-plaintext highlighter-rouge">Invoker</code> at application runtime, if using a Build Compatible Extension</li>
</ul>

<p>The <code class="language-plaintext highlighter-rouge">Invoker</code> then needs to be stored somewhere until the framework actually needs it.
When the time comes to invoke the method, the framework takes the <code class="language-plaintext highlighter-rouge">Invoker</code>, obtains an instance of <code class="language-plaintext highlighter-rouge">MyService</code> and all the parameter values, and calls</p>

<div class="language-java highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">invoker</span><span class="o">.</span><span class="na">invoke</span><span class="o">(</span><span class="n">myService</span><span class="o">,</span> <span class="k">new</span> <span class="nc">Object</span><span class="o">[]</span> <span class="o">{</span> <span class="s">"world"</span> <span class="o">})</span>
</code></pre></div></div>

<p>The return value is <code class="language-plaintext highlighter-rouge">"Hello world!"</code>, as expected.</p>

<h3 id="lookups">Lookups</h3>

<p>It is fairly common that some of the parameters the method accepts are CDI beans.
It is possible to configure the <code class="language-plaintext highlighter-rouge">InvokerBuilder</code> to resolve and instantiate a correct value for such parameter automatically.
In fact, this is possible also for the instance on which the method should be invoked.
The <code class="language-plaintext highlighter-rouge">InvokerBuilder</code> has methods <code class="language-plaintext highlighter-rouge">withInstanceLookup()</code> and <code class="language-plaintext highlighter-rouge">withArgumentLookup()</code> to configure that.</p>

<p>Returning back to the example above, if the CDI extension called <code class="language-plaintext highlighter-rouge">withInstanceLookup()</code> before calling <code class="language-plaintext highlighter-rouge">InvokerBuilder.build()</code>, it wouldn’t have to obtain the instance of <code class="language-plaintext highlighter-rouge">MyService</code> manually.
The invoker would do it automatically.
The invocation would just use <code class="language-plaintext highlighter-rouge">null</code> as the instance value:</p>

<div class="language-java highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">invoker</span><span class="o">.</span><span class="na">invoke</span><span class="o">(</span><span class="kc">null</span><span class="o">,</span> <span class="k">new</span> <span class="nc">Object</span><span class="o">[]</span> <span class="o">{</span> <span class="s">"world"</span> <span class="o">})</span>
</code></pre></div></div>

<p>The result is still the same: <code class="language-plaintext highlighter-rouge">"Hello world!"</code>.</p>

<h2 id="other-improvements">Other Improvements</h2>

<p>There’s a couple of quality of life improvements in this release, too.</p>

<p>Interceptors can now access the interceptor binding annotations from <code class="language-plaintext highlighter-rouge">InvocationContext</code>, using methods <code class="language-plaintext highlighter-rouge">getInterceptorBinding()</code> and <code class="language-plaintext highlighter-rouge">getInteceptorBindings()</code>.
This is technically a change in the Interceptors specification, but is most useful for CDI programmers, so we mention it here as well.</p>

<p>Producer methods and fields can now declare a <code class="language-plaintext highlighter-rouge">@Priority</code> directly (or obtain a priority from a stereotype); they no longer have to rely on the priority value of their declaring bean.
When both the producer and its declaring bean have a priority, the producer’s priority wins.</p>

<p>The newly added methods <code class="language-plaintext highlighter-rouge">BeanContainer.isMatchingBean()</code> and <code class="language-plaintext highlighter-rouge">isMatchingEvent()</code> provide programmatic access to the typesafe resolution and observer resolution rules.
This is useful for frameworks that want to perform the same matching as CDI, but don’t want to reimplement the rules themselves.</p>

<p>The newly added method <code class="language-plaintext highlighter-rouge">BeanContainer.getContexts()</code> returns context objects of all registered contexts for given scope, regardless of whether they are active or inactive.
This is useful for authors of Build Compatible Extensions, who don’t provide a context object to the container directly.
Instead, they provide a <em>class</em> of the context object, and they need to use this method to gain access to the context object which the CDI container creates internally.</p>

<h2 id="deprecations">Deprecations</h2>

<p>CDI 4.1 prepares for removing a dependency on Unified EL from the core CDI API (<code class="language-plaintext highlighter-rouge">cdi-api.jar</code>).
This dependency is very narrow and really only useful for application server authors, but it’s still there.</p>

<p>Specifically, there are 2 methods on the <code class="language-plaintext highlighter-rouge">BeanManager</code> interface that use EL types in their signatures:</p>

<ul>
  <li><code class="language-plaintext highlighter-rouge">getELResolver()</code>, which returns <code class="language-plaintext highlighter-rouge">ELResolver</code></li>
  <li><code class="language-plaintext highlighter-rouge">wrapExpressionFactory()</code>, which accepts and returns <code class="language-plaintext highlighter-rouge">ExpressionFactory</code></li>
</ul>

<p>These 2 methods are deprecated in CDI 4.1 and shall be removed in CDI 5.0.</p>

<p>The suggested replacement is the <code class="language-plaintext highlighter-rouge">ELAwareBeanManager</code> interface, which extends <code class="language-plaintext highlighter-rouge">BeanManager</code> and contains the same 2 methods, but exists outside of the core CDI API, in a supplemental CDI EL API artifact (<code class="language-plaintext highlighter-rouge">cdi-el-api.jar</code>).</p>

<p>As mentioned above, these methods are mainly used by application servers, so this shouldn’t really affect CDI users.
Also, CDI users don’t have to consume the new supplemental artifact; compiling against the existing CDI API is fine.</p>

<h2 id="cdi-ee-specification-moved">CDI EE Specification Moved</h2>

<p>This is more of a curiosity from user perspective, but relatively important change internally.</p>

<p>The <em>CDI in Jakarta EE</em> part of the CDI specification, or <em>CDI EE</em> for short, was moved from the CDI specification to the Jakarta EE Platform specification.
Together with that, the corresponding part of the CDI TCK (the <code class="language-plaintext highlighter-rouge">web</code> module, basically) was moved to the Jakarta EE Platform TCK.</p>

<p>This doesn’t affect CDI users, but is important for CDI implementations.</p>

<h2 id="conclusion">Conclusion</h2>

<p>CDI 4.1 is not a huge release, but it contains improvements useful for both application developers and framework authors.
If you have any questions, the friendly mailing list <code class="language-plaintext highlighter-rouge">cdi-dev@eclipse.org</code> is a great place to ask!</p>]]></content><author><name>ladt</name></author><category term="development-tips" /><summary type="html"><![CDATA[If you’re following the activity on the CDI repository, or in Jakarta EE in general, you might have noticed that the CDI 4.1 release is coming soon. In this short post, we’ll take a look at what’s new in the wonderful world of CDI.]]></summary></entry><entry><title type="html">Jakarta CDI 4.0 Draft Specification</title><link href="https://jakartaee.github.io/cdi/2022/01/25/400-RC3-spec.html" rel="alternate" type="text/html" title="Jakarta CDI 4.0 Draft Specification" /><published>2022-01-25T01:00:00+00:00</published><updated>2022-01-25T01:00:00+00:00</updated><id>https://jakartaee.github.io/cdi/2022/01/25/400-RC3-spec</id><content type="html" xml:base="https://jakartaee.github.io/cdi/2022/01/25/400-RC3-spec.html"><![CDATA[<p>A draft of the 4.0 CDI specification is available in the current build of the 4.0.0-RC3 API <a href="https://ci.eclipse.org/cdi/job/CDI%20Release-JDK11/25/artifact/spec/target/generated-docs/jakarta-cdi-spec-4.0.pdf">jakarta-cdi-spec-4.0.pdf</a>.</p>

<p>The Latest CDI API and TCK releases are 4.0.0-RC3 and can be found in maven central:</p>

<ul>
  <li><a href="https://search.maven.org/artifact/jakarta.enterprise/jakarta.enterprise.cdi-api/4.0.0-RC3/jar">jakarta.enterprise:jakarta.enterprise.cdi-api:4.0.0-RC3</a></li>
  <li><a href="https://search.maven.org/artifact/jakarta.enterprise/cdi-tck-core-impl/4.0.0-RC3/jar">jakarta.enterprise:cdi-tck-core-impl:4.0.0-RC3</a></li>
</ul>

<p>The TCK dist bundle is also availabe from the Eclipse downloads:
<a href="https://download.eclipse.org/ee4j/cdi/4.0/cdi-tck-4.0.0-RC3-dist.zip">cdi-tck-4.0.0-RC3-dist.zip</a></p>]]></content><author><name>starksm</name></author><category term="announcement" /><summary type="html"><![CDATA[A draft of the 4.0 CDI specification is available in the current build of the 4.0.0-RC3 API jakarta-cdi-spec-4.0.pdf.]]></summary></entry><entry><title type="html">You already know Build Compatible Extensions</title><link href="https://jakartaee.github.io/cdi/2021/12/03/you-know-build-compatible-extensions.html" rel="alternate" type="text/html" title="You already know Build Compatible Extensions" /><published>2021-12-03T00:00:00+00:00</published><updated>2021-12-03T00:00:00+00:00</updated><id>https://jakartaee.github.io/cdi/2021/12/03/you-know-build-compatible-extensions</id><content type="html" xml:base="https://jakartaee.github.io/cdi/2021/12/03/you-know-build-compatible-extensions.html"><![CDATA[<p>As you have learned from a <a href="https://jakartaee.github.io/cdi/2021/10/25/way-to-cdi4.html">previous post</a>, CDI Lite comes with a new extension API called <em>Build Compatible Extensions</em>.
In this post, you will learn more about this API by comparison with <em>Portable Extensions</em> and my hope is that by the end, you will see that <em>you already know Build Compatible Extensions</em>.</p>

<p>If you don’t know Portable Extensions, don’t worry.
The Build Compatible Extensions API has detailed documentation and all examples in this text should be easy to follow for anyone.</p>

<h2 id="extension-api">Extension API</h2>

<p>Build Compatible Extensions, similarly to Portable Extensions, are service providers for the <code class="language-plaintext highlighter-rouge">BuildCompatibleExtension</code> interface.
Contrary to Portable Extensions, Build Compatible Extensions do not declare observer methods for CDI events.
This is a major design goal of the entire CDI Lite effort: make it possible to perform bean discovery before the application is started, such as during compilation.
At that point in time, the CDI container obviously doesn’t exist, so it can’t deliver events.</p>

<p>That said, Build Compatible Extensions are still pretty close to what you’re used to.
Instead of observer methods, you declare methods annotated with one of the execution phase annotations.
On these methods, you then declare parameters that let you affect the bean discovery process.
Each execution phase allows a certain set of parameter types to be declared.</p>

<p>The Build Compatible Extensions API has 5 execution phases.
These phases roughly correspond to Portable Extensions lifecycle events:</p>

<table>
  <thead>
    <tr>
      <th>Build Compatible Extensions</th>
      <th>Portable Extensions</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">@Discovery</code></td>
      <td><code class="language-plaintext highlighter-rouge">BeforeBeanDiscovery</code></td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">@Enhancement</code></td>
      <td><code class="language-plaintext highlighter-rouge">ProcessAnnotatedType</code></td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">@Registration</code></td>
      <td><code class="language-plaintext highlighter-rouge">ProcessBean</code>, <code class="language-plaintext highlighter-rouge">ProcessObserverMethod</code> (read-only)</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">@Synthesis</code></td>
      <td><code class="language-plaintext highlighter-rouge">AfterBeanDiscovery</code></td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">@Validation</code></td>
      <td><code class="language-plaintext highlighter-rouge">AfterDeploymentValidation</code></td>
    </tr>
  </tbody>
</table>

<p>This covers the most important events in Portable Extensions.
One significant part is intentionally missing, and that’s an equivalent of the <code class="language-plaintext highlighter-rouge">ProcessBeanAttributes</code> event, plus the modification part of <code class="language-plaintext highlighter-rouge">ProcessObserverMethod</code>.
If deemed necessary, these could be added to Build Compatible Extensions in the future.</p>

<p>A simple <em>Hello, world!</em> extension would look like this:</p>

<div class="language-java highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1">// the corresponding META-INF/services/jakarta.enterprise.inject.build.compatible.spi.BuildCompatibleExtension file must also exist</span>
<span class="kd">public</span> <span class="kd">class</span> <span class="nc">MyExtension</span> <span class="kd">implements</span> <span class="nc">BuildCompatibleExtension</span> <span class="o">{</span>
    <span class="nd">@Discovery</span>
    <span class="kd">public</span> <span class="kt">void</span> <span class="nf">hello</span><span class="o">(</span><span class="nc">Messages</span> <span class="n">msg</span><span class="o">)</span> <span class="o">{</span>
        <span class="n">msg</span><span class="o">.</span><span class="na">info</span><span class="o">(</span><span class="s">"Hello, world!"</span><span class="o">);</span>
    <span class="o">}</span>
<span class="o">}</span>
</code></pre></div></div>

<p><code class="language-plaintext highlighter-rouge">Messages</code> is one of the types that extension methods can declare as a parameter.
Let’s take a look at all the phases and compare them to Portable Extensions in more detail.</p>

<h3 id="discovery">@Discovery</h3>

<p>In <code class="language-plaintext highlighter-rouge">@Discovery</code>, you can add types to be scanned during bean discovery and register custom meta-annotations.
Extension methods annotated <code class="language-plaintext highlighter-rouge">@Discovery</code> can declare parameters of these types:</p>

<ul>
  <li><code class="language-plaintext highlighter-rouge">MetaAnnotations</code>: register custom meta-annotations (qualifiers, interceptor bindings, stereotypes, and scopes)</li>
  <li><code class="language-plaintext highlighter-rouge">ScannedClasses</code>: add types to the set of types discovered during type discovery, so that they are scanned during bean discovery</li>
  <li><code class="language-plaintext highlighter-rouge">Messages</code>: logging and validation</li>
</ul>

<p>This is very similar to the <code class="language-plaintext highlighter-rouge">BeforeBeanDiscovery</code> event:</p>

<table>
  <thead>
    <tr>
      <th>Build Compatible Extensions</th>
      <th>Portable Extensions</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">ScannedClasses.add</code></td>
      <td><code class="language-plaintext highlighter-rouge">BeforeBeanDiscovery.addAnnotatedType</code></td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">MetaAnnotations.addQualifier</code></td>
      <td><code class="language-plaintext highlighter-rouge">BeforeBeanDiscovery.configureQualifier</code></td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">MetaAnnotations.addInterceptorBinding</code></td>
      <td><code class="language-plaintext highlighter-rouge">BeforeBeanDiscovery.configureInterceptorBinding</code></td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">MetaAnnotations.addStereotype</code></td>
      <td><code class="language-plaintext highlighter-rouge">BeforeBeanDiscovery.addStereotype</code></td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">MetaAnnotations.addContext</code></td>
      <td><code class="language-plaintext highlighter-rouge">BeforeBeanDiscovery.addScope</code> + <code class="language-plaintext highlighter-rouge">AfterBeanDiscovery.addContext</code></td>
    </tr>
  </tbody>
</table>

<p>One noticeable difference is that when adding a custom scope, you don’t provide a <em>context object</em>.
Instead, you provide a <em>class</em> of the context object, which is then instantiated at runtime (and so must have a public zero-parameter constructor).</p>

<h3 id="enhancement">@Enhancement</h3>

<p>In <code class="language-plaintext highlighter-rouge">@Enhancement</code>, you can look at discovered types and modify annotations on them.
Extension methods annotated <code class="language-plaintext highlighter-rouge">@Enhancement</code> can declare parameters of these types:</p>

<ul>
  <li><code class="language-plaintext highlighter-rouge">ClassInfo</code>: inspect classes that satisfy given criteria (see below)</li>
  <li><code class="language-plaintext highlighter-rouge">MethodInfo</code>: inspect methods that satisfy given criteria (see below)</li>
  <li><code class="language-plaintext highlighter-rouge">FieldInfo</code>: inspect fields that satisfy given criteria (see below)</li>
  <li><code class="language-plaintext highlighter-rouge">ClassConfig</code>: transform annotations on classes that satisfy given criteria (see below)</li>
  <li><code class="language-plaintext highlighter-rouge">MethodConfig</code>: transform annotations on methods that satisfy given criteria (see below)</li>
  <li><code class="language-plaintext highlighter-rouge">FieldConfig</code>: transform annotations on fields that satisfy given criteria (see below)</li>
  <li><code class="language-plaintext highlighter-rouge">Types</code>: utility to create instances of <code class="language-plaintext highlighter-rouge">Type</code></li>
  <li><code class="language-plaintext highlighter-rouge">Messages</code>: logging and validation</li>
</ul>

<p>Each <code class="language-plaintext highlighter-rouge">@Enhancement</code> method must declare exactly 1 parameter of type <code class="language-plaintext highlighter-rouge">ClassInfo</code>, <code class="language-plaintext highlighter-rouge">MethodInfo</code>, <code class="language-plaintext highlighter-rouge">FieldInfo</code>, <code class="language-plaintext highlighter-rouge">ClassConfig</code>, <code class="language-plaintext highlighter-rouge">MethodConfig</code>, or <code class="language-plaintext highlighter-rouge">FieldConfig</code>.</p>

<p>When the method declares a parameter of type <code class="language-plaintext highlighter-rouge">ClassInfo</code> or <code class="language-plaintext highlighter-rouge">ClassConfig</code>, it is called once for each matching type.
When it declares a parameter of type <code class="language-plaintext highlighter-rouge">MethodInfo</code> or <code class="language-plaintext highlighter-rouge">MethodConfig</code>, it is called once for each method and constructor of each matching type.
Finally, when it declares a parameter of type <code class="language-plaintext highlighter-rouge">FieldInfo</code> or <code class="language-plaintext highlighter-rouge">FieldConfig</code>, it is called once for each field of each matching type.</p>

<p>How are these “matching types” determined?
The <code class="language-plaintext highlighter-rouge">@Enhancement</code> annotation itself has members that, collectively, express this set:</p>

<ul>
  <li><code class="language-plaintext highlighter-rouge">types</code> is a simple set of matching types – this member is mandatory;</li>
  <li><code class="language-plaintext highlighter-rouge">withSubtypes</code> is a boolean flag that says whether all subtypes of given <code class="language-plaintext highlighter-rouge">types</code> are also matching;</li>
  <li><code class="language-plaintext highlighter-rouge">withAnnotations</code> is a set of annotation types that must be present on the types so that they match.</li>
</ul>

<p>The <code class="language-plaintext highlighter-rouge">types</code> and <code class="language-plaintext highlighter-rouge">withSubtypes</code> members corresponds to a type argument that you would apply to the <code class="language-plaintext highlighter-rouge">ProcessAnnotatedType</code> generic event type.
The <code class="language-plaintext highlighter-rouge">withAnnotations</code> member corresponds to the <code class="language-plaintext highlighter-rouge">@WithAnnotations</code> annotation.</p>

<p>As an example, let’s move a qualifier from one class to another:</p>

<div class="language-java highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1">// 1. a qualifier annotation</span>
<span class="nd">@Qualifier</span>
<span class="nd">@Retention</span><span class="o">(</span><span class="no">RUNTIME</span><span class="o">)</span>
<span class="kd">public</span> <span class="nd">@interface</span> <span class="nc">MyQualifier</span> <span class="o">{</span>
<span class="o">}</span>

<span class="c1">// 2. a service interface</span>
<span class="kd">public</span> <span class="kd">interface</span> <span class="nc">MyService</span> <span class="o">{</span>
    <span class="nc">String</span> <span class="nf">hello</span><span class="o">();</span>
<span class="o">}</span>

<span class="c1">// 3. two implementations, one with qualifier and the other unqualified</span>
<span class="nd">@Singleton</span>
<span class="nd">@MyQualifier</span>
<span class="kd">public</span> <span class="kd">class</span> <span class="nc">MyFooService</span> <span class="kd">implements</span> <span class="nc">MyService</span> <span class="o">{</span>
    <span class="nd">@Override</span>
    <span class="kd">public</span> <span class="nc">String</span> <span class="nf">hello</span><span class="o">()</span> <span class="o">{</span>
        <span class="k">return</span> <span class="s">"foo"</span><span class="o">;</span>
    <span class="o">}</span>
<span class="o">}</span>

<span class="nd">@Singleton</span>
<span class="kd">public</span> <span class="kd">class</span> <span class="nc">MyBarService</span> <span class="kd">implements</span> <span class="nc">MyService</span> <span class="o">{</span>
    <span class="nd">@Override</span>
    <span class="kd">public</span> <span class="nc">String</span> <span class="nf">hello</span><span class="o">()</span> <span class="o">{</span>
        <span class="k">return</span> <span class="s">"bar"</span><span class="o">;</span>
    <span class="o">}</span>
<span class="o">}</span>

<span class="c1">// 4. a class that uses the service</span>
<span class="nd">@Singleton</span>
<span class="kd">public</span> <span class="kd">class</span> <span class="nc">MyServiceUser</span> <span class="o">{</span>
    <span class="nd">@Inject</span>
    <span class="nd">@MyQualifier</span>
    <span class="nc">MyService</span> <span class="n">myService</span><span class="o">;</span>
<span class="o">}</span>

<span class="c1">// 5. the extension</span>
<span class="kd">public</span> <span class="kd">class</span> <span class="nc">MyExtension</span> <span class="kd">implements</span> <span class="nc">BuildCompatibleExtension</span> <span class="o">{</span>
    <span class="nd">@Enhancement</span><span class="o">(</span><span class="n">types</span> <span class="o">=</span> <span class="nc">MyFooService</span><span class="o">.</span><span class="na">class</span><span class="o">)</span>
    <span class="kd">public</span> <span class="kt">void</span> <span class="nf">foo</span><span class="o">(</span><span class="nc">ClassConfig</span> <span class="n">clazz</span><span class="o">)</span> <span class="o">{</span>
        <span class="n">clazz</span><span class="o">.</span><span class="na">removeAnnotation</span><span class="o">(</span><span class="n">it</span> <span class="o">-&gt;</span> <span class="n">it</span><span class="o">.</span><span class="na">name</span><span class="o">().</span><span class="na">equals</span><span class="o">(</span><span class="nc">MyQualifier</span><span class="o">.</span><span class="na">class</span><span class="o">.</span><span class="na">getName</span><span class="o">()));</span>
    <span class="o">}</span>

    <span class="nd">@Enhancement</span><span class="o">(</span><span class="n">types</span> <span class="o">=</span> <span class="nc">MyBarService</span><span class="o">.</span><span class="na">class</span><span class="o">)</span>
    <span class="kd">public</span> <span class="kt">void</span> <span class="nf">bar</span><span class="o">(</span><span class="nc">ClassConfig</span> <span class="n">clazz</span><span class="o">)</span> <span class="o">{</span>
        <span class="n">clazz</span><span class="o">.</span><span class="na">addAnnotation</span><span class="o">(</span><span class="nc">MyQualifier</span><span class="o">.</span><span class="na">class</span><span class="o">);</span>
    <span class="o">}</span>
<span class="o">}</span>
</code></pre></div></div>

<p>The API is used somewhat differently than <code class="language-plaintext highlighter-rouge">ProcessAnnotatedType</code>, because in Portable Extensions, you first have to get an <code class="language-plaintext highlighter-rouge">AnnotatedTypeConfigurator</code>.
From there, however, the correspondence is pretty clear:</p>

<table>
  <thead>
    <tr>
      <th>Build Compatible Extensions</th>
      <th>Portable Extensions</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">ClassConfig.info</code></td>
      <td><code class="language-plaintext highlighter-rouge">AnnotatedTypeConfigurator.getAnnotated</code></td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">ClassConfig.addAnnotation</code></td>
      <td><code class="language-plaintext highlighter-rouge">AnnotatedTypeConfigurator.add</code></td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">ClassConfig.removeAnnotation</code></td>
      <td><code class="language-plaintext highlighter-rouge">AnnotatedTypeConfigurator.remove</code></td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">ClassConfig.removeAllAnnotations</code></td>
      <td><code class="language-plaintext highlighter-rouge">AnnotatedTypeConfigurator.removeAll</code></td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">ClassConfig.constructors</code></td>
      <td><code class="language-plaintext highlighter-rouge">AnnotatedTypeConfigurator.constructors</code></td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">ClassConfig.methods</code></td>
      <td><code class="language-plaintext highlighter-rouge">AnnotatedTypeConfigurator.methods</code></td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">ClassConfig.fields</code></td>
      <td><code class="language-plaintext highlighter-rouge">AnnotatedTypeConfigurator.fields</code></td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">MethodConfig.info</code></td>
      <td><code class="language-plaintext highlighter-rouge">AnnotatedMethodConfigurator.getAnnotated</code>, <code class="language-plaintext highlighter-rouge">AnnotatedConstructorConfigurator.getAnnotated</code></td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">MethodConfig.addAnnotation</code></td>
      <td><code class="language-plaintext highlighter-rouge">AnnotatedMethodConfigurator.add</code>, <code class="language-plaintext highlighter-rouge">AnnotatedConstructorConfigurator.add</code></td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">MethodConfig.removeAnnotation</code></td>
      <td><code class="language-plaintext highlighter-rouge">AnnotatedMethodConfigurator.remove</code>, <code class="language-plaintext highlighter-rouge">AnnotatedConstructorConfigurator.remove</code></td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">MethodConfig.removeAllAnnotations</code></td>
      <td><code class="language-plaintext highlighter-rouge">AnnotatedMethodConfigurator.removeAll</code>, <code class="language-plaintext highlighter-rouge">AnnotatedConstructorConfigurator.removeAll</code></td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">MethodConfig.params</code></td>
      <td><code class="language-plaintext highlighter-rouge">AnnotatedMethodConfigurator.params</code>, <code class="language-plaintext highlighter-rouge">AnnotatedConstructorConfigurator.params</code></td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">ParameterConfig.info</code></td>
      <td><code class="language-plaintext highlighter-rouge">AnnotatedParameterConfigurator.getAnnotated</code></td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">ParameterConfig.addAnnotation</code></td>
      <td><code class="language-plaintext highlighter-rouge">AnnotatedParameterConfigurator.add</code></td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">ParameterConfig.removeAnnotation</code></td>
      <td><code class="language-plaintext highlighter-rouge">AnnotatedParameterConfigurator.remove</code></td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">ParameterConfig.removeAllAnnotations</code></td>
      <td><code class="language-plaintext highlighter-rouge">AnnotatedParameterConfigurator.removeAll</code></td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">FieldConfig.info</code></td>
      <td><code class="language-plaintext highlighter-rouge">AnnotatedFieldConfigurator.getAnnotated</code></td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">FieldConfig.addAnnotation</code></td>
      <td><code class="language-plaintext highlighter-rouge">AnnotatedFieldConfigurator.add</code></td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">FieldConfig.removeAnnotation</code></td>
      <td><code class="language-plaintext highlighter-rouge">AnnotatedFieldConfigurator.remove</code></td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">FieldConfig.removeAllAnnotations</code></td>
      <td><code class="language-plaintext highlighter-rouge">AnnotatedFieldConfigurator.removeAll</code></td>
    </tr>
  </tbody>
</table>

<p><code class="language-plaintext highlighter-rouge">ProcessAnnotatedType.getAnnotatedType</code> corresponds to declaring a parameter of type <code class="language-plaintext highlighter-rouge">ClassInfo</code>.
That type is described below, in the <em>Langugae Model</em> section.</p>

<p>Careful reader will note that <code class="language-plaintext highlighter-rouge">ProcessAnnotatedType</code> allows creating a whole new <code class="language-plaintext highlighter-rouge">AnnotatedType</code> manually and supplying it to the container.
Build Compatible Extensions do not allow this style of usage, only the simplified and more straightforward <code class="language-plaintext highlighter-rouge">*Configurator</code> style.</p>

<h3 id="registration">@Registration</h3>

<p>In <code class="language-plaintext highlighter-rouge">@Registration</code>, you can look at registered beans, interceptors, and observers.
Extension methods annotated <code class="language-plaintext highlighter-rouge">@Registration</code> can declare parameters of these types:</p>

<ul>
  <li><code class="language-plaintext highlighter-rouge">BeanInfo</code>: look at registered beans that satisfy given criteria (see below)</li>
  <li><code class="language-plaintext highlighter-rouge">InterceptorInfo</code>: look at registered interceptors that satisfy given criteria (see below)</li>
  <li><code class="language-plaintext highlighter-rouge">ObserverInfo</code>: look at registered observers that satisfy given criteria (see below)</li>
  <li><code class="language-plaintext highlighter-rouge">Types</code>: utility to create instances of <code class="language-plaintext highlighter-rouge">Type</code></li>
  <li><code class="language-plaintext highlighter-rouge">Messages</code>: logging and validation</li>
</ul>

<p>Each <code class="language-plaintext highlighter-rouge">@Registration</code> method must declare exactly 1 parameter of type <code class="language-plaintext highlighter-rouge">BeanInfo</code>, <code class="language-plaintext highlighter-rouge">InterceptorInfo</code>, or <code class="language-plaintext highlighter-rouge">ObserverInfo</code>.</p>

<p>When the method declares a parameter of type <code class="language-plaintext highlighter-rouge">BeanInfo</code>, it is called once for each bean whose set of bean types contains at least one given type.
When it declares a parameter of type <code class="language-plaintext highlighter-rouge">InterceptorInfo</code>, it is called once for each interceptor whose set of bean types contains at least one given type.
Finally, when it declares a parameter of type <code class="language-plaintext highlighter-rouge">ObserverInfo</code>, it is called once for each observer whose observed event type is assignable to at least one given type.</p>

<p>Similarly to <code class="language-plaintext highlighter-rouge">@Enhancement</code>, these “given types” come from the <code class="language-plaintext highlighter-rouge">@Registration</code> annotation itself.
The annotation has a single mandatory member called <code class="language-plaintext highlighter-rouge">types</code> whose value is the set of “given types”.
The <code class="language-plaintext highlighter-rouge">types</code> member corresponds to a type argument that you would apply to the <code class="language-plaintext highlighter-rouge">ProcessBean</code> or <code class="language-plaintext highlighter-rouge">ProcessObserverMethod</code> generic event types.</p>

<p>Again, Portable Extensions are somewhat different in usage, but there’s a direct correspondence:</p>

<table>
  <thead>
    <tr>
      <th>Build Compatible Extensions</th>
      <th>Portable Extensions</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">BeanInfo</code></td>
      <td><code class="language-plaintext highlighter-rouge">Bean</code> obtained from <code class="language-plaintext highlighter-rouge">ProcessBean</code></td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">InterceptorInfo</code></td>
      <td><code class="language-plaintext highlighter-rouge">Interceptor</code> obtained from <code class="language-plaintext highlighter-rouge">ProcessBean</code></td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">ObserverInfo</code></td>
      <td><code class="language-plaintext highlighter-rouge">ObserverMethod</code> obtained from <code class="language-plaintext highlighter-rouge">ProcessObserverMethod</code></td>
    </tr>
  </tbody>
</table>

<h3 id="synthesis">@Synthesis</h3>

<p>In <code class="language-plaintext highlighter-rouge">@Synthesis</code>, you can register synthetic beans and observers.
Extension methods annotated <code class="language-plaintext highlighter-rouge">@Synthesis</code> can declare parameters of these types:</p>

<ul>
  <li><code class="language-plaintext highlighter-rouge">SyntheticComponents</code>: register synthetic beans and observers</li>
  <li><code class="language-plaintext highlighter-rouge">Types</code>: utility to create instances of <code class="language-plaintext highlighter-rouge">Type</code></li>
  <li><code class="language-plaintext highlighter-rouge">Messages</code>: logging and validation</li>
</ul>

<p>As an example, let’s create a synthetic bean.
Synthetic observers are very similar.</p>

<div class="language-java highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1">// 1. a bean class</span>
<span class="kd">public</span> <span class="kd">class</span> <span class="nc">MyPojo</span> <span class="o">{</span>
    <span class="kd">public</span> <span class="kd">final</span> <span class="nc">String</span> <span class="n">data</span><span class="o">;</span>

    <span class="kd">public</span> <span class="nf">MyPojo</span><span class="o">(</span><span class="nc">String</span> <span class="n">data</span><span class="o">)</span> <span class="o">{</span>
        <span class="k">this</span><span class="o">.</span><span class="na">data</span> <span class="o">=</span> <span class="n">data</span><span class="o">;</span>
    <span class="o">}</span>
<span class="o">}</span>

<span class="c1">// 2. bean creation function</span>
<span class="kd">public</span> <span class="kd">class</span> <span class="nc">MyPojoCreator</span> <span class="kd">implements</span> <span class="nc">SyntheticBeanCreator</span><span class="o">&lt;</span><span class="nc">MyPojo</span><span class="o">&gt;</span> <span class="o">{</span>
    <span class="nd">@Override</span>
    <span class="kd">public</span> <span class="nc">MyPojo</span> <span class="nf">create</span><span class="o">(</span><span class="nc">Instance</span><span class="o">&lt;</span><span class="nc">Object</span><span class="o">&gt;</span> <span class="n">lookup</span><span class="o">,</span> <span class="nc">Parameters</span> <span class="n">params</span><span class="o">)</span> <span class="o">{</span>
        <span class="nc">String</span> <span class="n">name</span> <span class="o">=</span> <span class="n">params</span><span class="o">.</span><span class="na">get</span><span class="o">(</span><span class="s">"name"</span><span class="o">,</span> <span class="nc">String</span><span class="o">.</span><span class="na">class</span><span class="o">);</span>
        <span class="k">return</span> <span class="k">new</span> <span class="nf">MyPojo</span><span class="o">(</span><span class="s">"Hello "</span> <span class="o">+</span> <span class="n">name</span><span class="o">);</span>
    <span class="o">}</span>
<span class="o">}</span>

<span class="c1">// 3. bean disposal function</span>
<span class="kd">public</span> <span class="kd">static</span> <span class="kd">class</span> <span class="nc">MyPojoDisposer</span> <span class="kd">implements</span> <span class="nc">SyntheticBeanDisposer</span><span class="o">&lt;</span><span class="nc">MyPojo</span><span class="o">&gt;</span> <span class="o">{</span>
    <span class="nd">@Override</span>
    <span class="kd">public</span> <span class="kt">void</span> <span class="nf">dispose</span><span class="o">(</span><span class="nc">MyPojo</span> <span class="n">instance</span><span class="o">,</span> <span class="nc">Instance</span><span class="o">&lt;</span><span class="nc">Object</span><span class="o">&gt;</span> <span class="n">lookup</span><span class="o">,</span> <span class="nc">Parameters</span> <span class="n">params</span><span class="o">)</span> <span class="o">{</span>
        <span class="nc">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">println</span><span class="o">(</span><span class="s">"disposing "</span> <span class="o">+</span> <span class="n">instance</span><span class="o">.</span><span class="na">data</span><span class="o">);</span>
    <span class="o">}</span>
<span class="o">}</span>

<span class="c1">// 4. the extension</span>
<span class="kd">public</span> <span class="kd">static</span> <span class="kd">class</span> <span class="nc">MyExtension</span> <span class="kd">implements</span> <span class="nc">BuildCompatibleExtension</span> <span class="o">{</span>
    <span class="nd">@Synthesis</span>
    <span class="kd">public</span> <span class="kt">void</span> <span class="nf">synthesise</span><span class="o">(</span><span class="nc">SyntheticComponents</span> <span class="n">syn</span><span class="o">)</span> <span class="o">{</span>
        <span class="n">syn</span><span class="o">.</span><span class="na">addBean</span><span class="o">(</span><span class="nc">MyPojo</span><span class="o">.</span><span class="na">class</span><span class="o">)</span>
                <span class="o">.</span><span class="na">type</span><span class="o">(</span><span class="nc">MyPojo</span><span class="o">.</span><span class="na">class</span><span class="o">)</span>
                <span class="o">.</span><span class="na">withParam</span><span class="o">(</span><span class="s">"name"</span><span class="o">,</span> <span class="s">"World"</span><span class="o">)</span>
                <span class="o">.</span><span class="na">createWith</span><span class="o">(</span><span class="nc">MyPojoCreator</span><span class="o">.</span><span class="na">class</span><span class="o">)</span>
                <span class="o">.</span><span class="na">disposeWith</span><span class="o">(</span><span class="nc">MyPojoDisposer</span><span class="o">.</span><span class="na">class</span><span class="o">);</span>
    <span class="o">}</span>
<span class="o">}</span>
</code></pre></div></div>

<p>An important observation is that the <code class="language-plaintext highlighter-rouge">MyExtension</code> code runs during bean discovery, which may be during application compilation, while the <code class="language-plaintext highlighter-rouge">MyPojoCreator</code> and <code class="language-plaintext highlighter-rouge">MyPojoDisposer</code> functions run at runtime.
The <code class="language-plaintext highlighter-rouge">Parameters</code> map is transferred from the extension code to the runtime code.
What kind of parameter types are possible?
Essentially anything that you can put into an annotation, including annotations themselves.</p>

<p>Comparison with Portable Extensions is straightforward:</p>

<table>
  <thead>
    <tr>
      <th>Build Compatible Extensions</th>
      <th>Portable Extensions</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">SyntheticComponents.addBean</code></td>
      <td><code class="language-plaintext highlighter-rouge">AfterBeanDiscovery.addBean</code></td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">SyntheticComponents.addObserver</code></td>
      <td><code class="language-plaintext highlighter-rouge">AfterBeanDiscovery.addObserverMethod</code></td>
    </tr>
  </tbody>
</table>

<p>Similarly to <code class="language-plaintext highlighter-rouge">@Enhancement</code>, Build Compatible Extensions do not have an equivalent of creating a whole new <code class="language-plaintext highlighter-rouge">Bean</code> or <code class="language-plaintext highlighter-rouge">ObserverMethod</code> object from scratch.
Only the simplified and more straightforward <code class="language-plaintext highlighter-rouge">*Configurator</code> style is present.</p>

<h3 id="validation">@Validation</h3>

<p>In <code class="language-plaintext highlighter-rouge">@Validation</code>, you can perform custom validation.
Extension methods annotated <code class="language-plaintext highlighter-rouge">@Validation</code> can declare parameters of these types:</p>

<ul>
  <li><code class="language-plaintext highlighter-rouge">Messages</code>: logging and validation</li>
  <li><code class="language-plaintext highlighter-rouge">Types</code>: utility to create instances of <code class="language-plaintext highlighter-rouge">Type</code></li>
</ul>

<p>Comparison with Portable Extensions is obvious:</p>

<table>
  <thead>
    <tr>
      <th>Build Compatible Extensions</th>
      <th>Portable Extensions</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">Messages.error</code></td>
      <td><code class="language-plaintext highlighter-rouge">AfterDeploymentValidation.addDeploymentProblem</code></td>
    </tr>
  </tbody>
</table>

<p>At this point, you may be asking, what’s the real difference?
Isn’t this just a different set of names for existing concepts?
Is a new API truly necessary?</p>

<p>The answer, again, comes from the architectural constraint that all this must be implementable during application compilation.
This means the CDI container can’t be running, but it also means that using reflection is costly or even forbidden.
Portable Extensions, unfortunately, are very reflection-heavy.
That’s why, in addition to a new extension API, we also had to create a new <em>language model</em> API.
All those weird types called <code class="language-plaintext highlighter-rouge">ClassInfo</code> etc. are part of that.
In the following section, we’ll describe the API in more detail and compare with existing similar APIs.</p>

<h2 id="language-model">Language Model</h2>

<p>The <code class="language-plaintext highlighter-rouge">jakarta.enterprise.lang.model</code> API models the Java language from a high-level perspective.
It is completely reflection-free, though it may easily be implemented on top of reflection.
The core value is that it can also be implemented on top of other representations, such as <code class="language-plaintext highlighter-rouge">javax.lang.model</code> or Jandex.</p>

<p>The model is structured as a hierarchy of types.
The root in this hierarchy is <code class="language-plaintext highlighter-rouge">AnnotationTarget</code>.
That is anything that can be annotated:</p>

<ul>
  <li><em>declarations</em>, such as classes, methods or fields;</li>
  <li><em>types</em>, such as reference types, type variables or wildcard types.</li>
</ul>

<p>Annotations are represented by <code class="language-plaintext highlighter-rouge">AnnotationInfo</code>.
An <code class="language-plaintext highlighter-rouge">AnnotationInfo</code> has a <code class="language-plaintext highlighter-rouge">String</code>-keyed map of annotation members, represented by <code class="language-plaintext highlighter-rouge">AnnotationMember</code>.</p>

<table>
  <thead>
    <tr>
      <th>Build Compatible Extensions</th>
      <th>Portable Extensions</th>
      <th>Reflection</th>
      <th>Annotation Processing</th>
      <th>Jandex</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">AnnotationTarget</code></td>
      <td><code class="language-plaintext highlighter-rouge">jakarta.enterprise.inject.spi.Annotated</code></td>
      <td><code class="language-plaintext highlighter-rouge">java.lang.reflect.AnnotatedElement</code></td>
      <td><code class="language-plaintext highlighter-rouge">javax.lang.model.AnnotatedConstruct</code></td>
      <td><code class="language-plaintext highlighter-rouge">org.jboss.jandex.AnnotationTarget</code></td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">AnnotationInfo</code></td>
      <td>none, uses <code class="language-plaintext highlighter-rouge">java.lang.Annotation</code></td>
      <td>none</td>
      <td><code class="language-plaintext highlighter-rouge">javax.lang.model.AnnotationMirror</code></td>
      <td><code class="language-plaintext highlighter-rouge">org.jboss.jandex.AnnotationInstance</code></td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">AnnotationMember</code></td>
      <td>none<sup>1</sup></td>
      <td>none</td>
      <td><code class="language-plaintext highlighter-rouge">javax.lang.model.element.AnnotationValue</code></td>
      <td><code class="language-plaintext highlighter-rouge">org.jboss.jandex.AnnotationValue</code></td>
    </tr>
  </tbody>
</table>

<ol>
  <li>Reflective access is possible, but usually not necessary.</li>
</ol>

<p>As mentioned above, there are two kinds of <code class="language-plaintext highlighter-rouge">AnnotationTarget</code>s: declarations and types.
Therefore, we have <code class="language-plaintext highlighter-rouge">DeclarationInfo</code> as the top-level type for representing Java declarations, and <code class="language-plaintext highlighter-rouge">Type</code> as the top-level type for representing Java types.</p>

<p>Declarations are:</p>
<ul>
  <li>packages;</li>
  <li>classes, including interfaces, enums, annotations, and records;</li>
  <li>fields;</li>
  <li>methods, including constructors;</li>
  <li>method parameters;</li>
  <li>record components.</li>
</ul>

<table>
  <thead>
    <tr>
      <th>Build Compatible Extensions</th>
      <th>Portable Extensions</th>
      <th>Reflection</th>
      <th>Annotation Processing</th>
      <th>Jandex</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">DeclarationInfo</code></td>
      <td>none, just <code class="language-plaintext highlighter-rouge">jakarta.enterprise.inject.spi.Annotated</code></td>
      <td>none<sup>4</sup></td>
      <td><code class="language-plaintext highlighter-rouge">javax.lang.model.element.Element</code></td>
      <td>none, just <code class="language-plaintext highlighter-rouge">org.jboss.jandex.AnnotationTarget</code></td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">PackageInfo</code></td>
      <td>none<sup>1</sup></td>
      <td><code class="language-plaintext highlighter-rouge">java.lang.Package</code></td>
      <td><code class="language-plaintext highlighter-rouge">javax.lang.model.element.PackageElement</code></td>
      <td>none<sup>5</sup></td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">ClassInfo</code></td>
      <td><code class="language-plaintext highlighter-rouge">jakarta.enterprise.inject.spi.AnnotatedType</code><sup>2</sup></td>
      <td><code class="language-plaintext highlighter-rouge">java.lang.Class</code></td>
      <td><code class="language-plaintext highlighter-rouge">javax.lang.model.element.TypeElement</code></td>
      <td><code class="language-plaintext highlighter-rouge">org.jboss.jandex.ClassInfo</code></td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">FieldInfo</code></td>
      <td><code class="language-plaintext highlighter-rouge">jakarta.enterprise.inject.spi.AnnotatedField</code><sup>2</sup></td>
      <td><code class="language-plaintext highlighter-rouge">java.lang.reflect.Field</code></td>
      <td><code class="language-plaintext highlighter-rouge">javax.lang.model.element.VariableElement</code></td>
      <td><code class="language-plaintext highlighter-rouge">org.jboss.jandex.FieldInfo</code></td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">MethodInfo</code></td>
      <td><code class="language-plaintext highlighter-rouge">jakarta.enterprise.inject.spi.AnnotatedMethod</code>, <code class="language-plaintext highlighter-rouge">jakarta.enterprise.inject.spi.AnnotatedConstructor</code><sup>2</sup></td>
      <td><code class="language-plaintext highlighter-rouge">java.lang.reflect.Method</code>, <code class="language-plaintext highlighter-rouge">java.lang.reflect.Constructor</code></td>
      <td><code class="language-plaintext highlighter-rouge">javax.lang.model.element.ExecutableElement</code></td>
      <td><code class="language-plaintext highlighter-rouge">org.jboss.jandex.MethodInfo</code></td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">ParameterInfo</code></td>
      <td><code class="language-plaintext highlighter-rouge">jakarta.enterprise.inject.spi.AnnotatedParameter</code><sup>2</sup></td>
      <td><code class="language-plaintext highlighter-rouge">java.lang.reflect.Parameter</code></td>
      <td><code class="language-plaintext highlighter-rouge">javax.lang.model.element.VariableElement</code></td>
      <td><code class="language-plaintext highlighter-rouge">org.jboss.jandex.MethodParameterInfo</code></td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">RecordComponentInfo</code></td>
      <td>none<sup>3</sup></td>
      <td><code class="language-plaintext highlighter-rouge">java.lang.reflect.RecordComponent</code></td>
      <td><code class="language-plaintext highlighter-rouge">javax.lang.model.element.RecordComponentElement</code></td>
      <td><code class="language-plaintext highlighter-rouge">org.jboss.jandex.RecordComponentInfo</code></td>
    </tr>
  </tbody>
</table>

<ol>
  <li>Relies on reflection.</li>
  <li>Provides access to the corresponding reflection object.</li>
  <li>CDI doesn’t reflect the existence of records yet.</li>
  <li>There are types such as <code class="language-plaintext highlighter-rouge">java.lang.reflect.GenericDeclaration</code> or <code class="language-plaintext highlighter-rouge">java.lang.reflect.AccessibleObject</code>, but nothing directly corresponding,</li>
  <li>It is possible to obtain a <code class="language-plaintext highlighter-rouge">ClassInfo</code> for <code class="language-plaintext highlighter-rouge">package-info.class</code>,</li>
</ol>

<p>Types are:</p>
<ul>
  <li>the <code class="language-plaintext highlighter-rouge">void</code> pseudo-type;</li>
  <li>primitive types, such as <code class="language-plaintext highlighter-rouge">int</code>;</li>
  <li>class types, such as <code class="language-plaintext highlighter-rouge">String</code>;</li>
  <li>array types, such as <code class="language-plaintext highlighter-rouge">int[]</code> or <code class="language-plaintext highlighter-rouge">String[][]</code>;</li>
  <li>parameterized types, such as <code class="language-plaintext highlighter-rouge">List&lt;String&gt;</code>;</li>
  <li>type variables, such as <code class="language-plaintext highlighter-rouge">T</code> when used in a class or method that declares a type parameter <code class="language-plaintext highlighter-rouge">T</code>;</li>
  <li>wildcard types, such as <code class="language-plaintext highlighter-rouge">? extends Number</code>.</li>
</ul>

<table>
  <thead>
    <tr>
      <th>Build Compatible Extensions</th>
      <th>Portable Extensions</th>
      <th>Reflection</th>
      <th>Annotation Processing</th>
      <th>Jandex</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">Type</code></td>
      <td>none<sup>1</sup></td>
      <td><code class="language-plaintext highlighter-rouge">java.lang.reflect.Type</code><sup>2</sup></td>
      <td><code class="language-plaintext highlighter-rouge">javax.lang.model.type.TypeMirror</code></td>
      <td><code class="language-plaintext highlighter-rouge">org.jboss.jandex.Type</code></td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">VoidType</code></td>
      <td>none<sup>1</sup></td>
      <td><code class="language-plaintext highlighter-rouge">java.lang.Class</code><sup>2</sup></td>
      <td><code class="language-plaintext highlighter-rouge">javax.lang.model.type.NoType</code></td>
      <td><code class="language-plaintext highlighter-rouge">org.jboss.jandex.VoidType</code></td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">PrimitiveType</code></td>
      <td>none<sup>1</sup></td>
      <td><code class="language-plaintext highlighter-rouge">java.lang.Class</code><sup>2</sup></td>
      <td><code class="language-plaintext highlighter-rouge">javax.lang.model.type.PrimitiveType</code></td>
      <td><code class="language-plaintext highlighter-rouge">org.jboss.jandex.PrimitiveType</code></td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">ClassType</code></td>
      <td>none<sup>1</sup></td>
      <td><code class="language-plaintext highlighter-rouge">java.lang.Class</code><sup>2</sup></td>
      <td><code class="language-plaintext highlighter-rouge">javax.lang.model.type.DeclaredType</code></td>
      <td><code class="language-plaintext highlighter-rouge">org.jboss.jandex.ClassType</code></td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">ArrayType</code></td>
      <td>none<sup>1</sup></td>
      <td><code class="language-plaintext highlighter-rouge">java.lang.Class</code>, <code class="language-plaintext highlighter-rouge">java.lang.reflect.GenericArrayType</code><sup>2</sup></td>
      <td><code class="language-plaintext highlighter-rouge">javax.lang.model.type.ArrayType</code></td>
      <td><code class="language-plaintext highlighter-rouge">org.jboss.jandex.ArrayType</code></td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">ParameterizedType</code></td>
      <td>none<sup>1</sup></td>
      <td><code class="language-plaintext highlighter-rouge">java.lang.reflect.ParameterizedType</code><sup>2</sup></td>
      <td><code class="language-plaintext highlighter-rouge">javax.lang.model.type.DeclaredType</code></td>
      <td><code class="language-plaintext highlighter-rouge">org.jboss.jandex.ParameterizedType</code></td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">TypeVariable</code></td>
      <td>none<sup>1</sup></td>
      <td><code class="language-plaintext highlighter-rouge">java.lang.reflect.TypeVariable</code><sup>2</sup></td>
      <td><code class="language-plaintext highlighter-rouge">javax.lang.model.type.TypeVariable</code></td>
      <td><code class="language-plaintext highlighter-rouge">org.jboss.jandex.TypeVariable</code>, <code class="language-plaintext highlighter-rouge">org.jboss.jandex.UnresolvedTypeVariable</code></td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">WildcardType</code></td>
      <td>none<sup>1</sup></td>
      <td><code class="language-plaintext highlighter-rouge">java.lang.reflect.WildcardType</code><sup>2</sup></td>
      <td><code class="language-plaintext highlighter-rouge">javax.lang.model.type.WildcardType</code></td>
      <td><code class="language-plaintext highlighter-rouge">org.jboss.jandex.WildcardType</code></td>
    </tr>
  </tbody>
</table>

<ol>
  <li>Relies on reflection.</li>
  <li>There’s also an alternative hierarchy rooted at <code class="language-plaintext highlighter-rouge">java.lang.reflect.AnnotatedType</code>.</li>
</ol>

<h2 id="conclusion">Conclusion</h2>

<p>It’s been a ride, but you’ve seen the most important bits of the Build Compatible Extensions API.
You’ve also seen how it compares to other APIs, particularly to Portable Extensions.</p>

<p>By now, you hopefully realize that while there are some necessary differences, you would be able to write an extension just fine.
If not, the <code class="language-plaintext highlighter-rouge">cdi-dev</code> mailing list is a great place to ask!</p>]]></content><author><name>ladt</name></author><category term="development-tips" /><summary type="html"><![CDATA[As you have learned from a previous post, CDI Lite comes with a new extension API called Build Compatible Extensions. In this post, you will learn more about this API by comparison with Portable Extensions and my hope is that by the end, you will see that you already know Build Compatible Extensions.]]></summary></entry><entry><title type="html">Jakarta CDI GitHub Pages</title><link href="https://jakartaee.github.io/cdi/2021/10/26/pages-here.html" rel="alternate" type="text/html" title="Jakarta CDI GitHub Pages" /><published>2021-10-26T03:08:50+00:00</published><updated>2021-10-26T03:08:50+00:00</updated><id>https://jakartaee.github.io/cdi/2021/10/26/pages-here</id><content type="html" xml:base="https://jakartaee.github.io/cdi/2021/10/26/pages-here.html"><![CDATA[<h1 id="cdi-github-pages">CDI GitHub Pages</h1>

<p>The GitHub pages for Jakarta CDI has arrived. See the <a href="https://github.com/jakartaee/cdi/tree/master/docs/README.md">README.md</a> file for how to build the pages site locally, and how to create a blog entry.</p>]]></content><author><name>starksm</name></author><category term="announcement" /><summary type="html"><![CDATA[CDI GitHub Pages]]></summary></entry><entry><title type="html">On the Way to CDI 4.0</title><link href="https://jakartaee.github.io/cdi/2021/10/25/way-to-cdi4.html" rel="alternate" type="text/html" title="On the Way to CDI 4.0" /><published>2021-10-25T00:00:00+00:00</published><updated>2021-10-25T00:00:00+00:00</updated><id>https://jakartaee.github.io/cdi/2021/10/25/way-to-cdi4</id><content type="html" xml:base="https://jakartaee.github.io/cdi/2021/10/25/way-to-cdi4.html"><![CDATA[<p>As you probably know, work is well under way for projects aiming to land in Jakarta EE 10 space and CDI is no exception. In fact, the specification is close to being rounded up for its next major release hence it is the right time to summarize what is coming.</p>

<p>Here is a quick overview of impending changes; we’ll look into each of them separately:</p>

<ul>
  <li>Introduction of CDI Lite</li>
  <li>Change of default empty <code class="language-plaintext highlighter-rouge">beans.xml</code> discovery mode</li>
  <li>Removal of long deprecated API bits</li>
  <li>Quality of life improvements</li>
</ul>

<h2 id="introduction-of-cdi-lite">Introduction of CDI Lite</h2>

<p>The split of specification to CDI Full and CDI Lite is by far the biggest change coming in 4.0 and is therefore split into several parts.</p>

<h3 id="little-bit-of-history">Little Bit of History</h3>

<p>The <a href="http://www.cdi-spec.org/news/2020/03/09/CDI_for_the_future/">original proposal</a> for CDI Lite was published in March 2020 and if you browse <a href="http://www.eclipse.org/lists/cdi-dev">the CDI mailing list</a>, you’ll see that there have been many threads on this topic since then. And those discussions, meetings and proposals have been fruitful because later on, precisely in May 2021, a <a href="https://www.eclipse.org/lists/cdi-dev/msg00361.html">community vote</a> took place and decided that CDI Lite is about to happen. To this date, two projects are known to be working on a build-time CDI Lite implementation: Quarkus, through its ArC subproject, and OpenDI, which is based on top of Micronaut.</p>

<h3 id="what-is-and-isnt-lite">What is and isn’t Lite</h3>

<p>The specification was split into Lite and Full parts in a way that Lite defines a set of core features and Full then builds on top of it, expanding sets of rules and presenting additional features. This means that CDI Lite is simply a subset of CDI Full - you can use Lite APIs in a portable way in CDI Full environments and every CDI Full implementation has to also implement CDI Lite. That being said, CDI Full remains ‘runtime oriented’ as opposed to Lite implementations which are likely to focus on build-time environments even though the specification sets no limits in this regard.</p>

<p>Below is a list of CDI features that are now exclusive to CDI Full implementations:</p>

<ul>
  <li>Decorators</li>
  <li>Interception bound via <code class="language-plaintext highlighter-rouge">@Interceptors</code> annotation
    <ul>
      <li>Interceptors bound via interceptor binding annotations work perfectly well in CDI Lite</li>
    </ul>
  </li>
  <li>Specialization</li>
  <li>Passivation</li>
  <li>Conversation Scope
    <ul>
      <li>All other built-in scopes are present in CDI Lite</li>
    </ul>
  </li>
  <li>Portable Extensions
    <ul>
      <li>These are replaced by a new extension API which is described in the following paragraph</li>
    </ul>
  </li>
</ul>

<p>It is important to reiterate that existing applications are all considered to use CDI Full and as such will continue working unimpeded.</p>

<h3 id="introduction-of-build-compatible-extensions">Introduction of Build Compatible Extensions</h3>

<p>Portable Extensions are crucial for CDI extensibility but are also an ill fit for any build oriented framework. Therefore, an alternative extension SPI was proposed. This was covered in depth in a <a href="http://www.cdi-spec.org/news/2020/09/15/CDI_Lite_extension/">previous blog post</a> and has undergone many iterations since. However, its purpose stays ultimately the same - to provide an alternative for Portable Extensions that will work in all environments.</p>

<h3 id="new-underlying-metamodel">New Underlying Metamodel</h3>

<p>One of the goals of CDI Lite was to shake off as much reflection as possible. Nonetheless, current metamodel (<code class="language-plaintext highlighter-rouge">AnnotatedType</code> and friends) is very reflection-heavy which is why CDI Lite comes with new metamodel abstraction. Note that CDI Full and Portable Extensions will still use the old metamodel whereas CDI Lite and Build Compatible Extensions will use the new metamodel.</p>

<p>This metamodel is currently housed inside CDI JAR but there has been some interest in using it from other Jakarta projects so it might end up being shipped as a separate artifact.</p>

<h3 id="shipping-cdi-40-jar">Shipping CDI 4.0 JAR</h3>

<p>One of the questions on many meetings was around how to ship CDI JAR now that there is Lite and Full combined. The answer to that is that there is no clear way of achieving that without breaking existing applications through package name changes. Therefore, as a compromise, CDI will stay a single JAR containing all the APIs.</p>

<h2 id="change-of-default-empty-beansxml-discovery-mode">Change of Default Empty <code class="language-plaintext highlighter-rouge">beans.xml</code> Discovery Mode</h2>

<p>One notable change coming to CDI is the <a href="https://github.com/eclipse-ee4j/cdi/issues/500">discovery mode of bean archives containing empty <code class="language-plaintext highlighter-rouge">beans.xml</code></a>. These were formerly treated as explicit bean archives (i.e. having discovery mode <code class="language-plaintext highlighter-rouge">all</code>) but beginning with CDI 4.0, they will be considered as implicit bean archives (discovery mode <code class="language-plaintext highlighter-rouge">annotated</code>).</p>

<p>In other words, if a class in such an archive is to be recognized as a bean, it needs to have at least one bean defining annotation. It can be a breaking change which is why this change also comes with a backward compatible switch - all CDI Full products have to contain an option that switches the behavior to how it worked in the past. The option is of course a temporary measure to ease transition and applications are encouraged to adapt their bean archives accordingly in the long term.</p>

<p>For those interested in the history of this decision, there was a <a href="https://www.eclipse.org/lists/cdi-dev/msg00353.html">community survey</a>, posted via CDI mailing list, detailing the reasons and options with results visible <a href="https://docs.google.com/forms/d/e/1FAIpQLSes003JAWpieL6Rp80Js-vhuMcTril_olbnL2TBY5pM5PvVdA/viewanalytics">here</a>.</p>

<h2 id="removal-of-deprecated-api-bits">Removal of Deprecated API Bits</h2>

<p>CDI has been around for over a decade and as such has accumulated a bunch of deprecated APIs that were carried over and over into each subsequent version. A cleanup was already well overdue, so <a href="https://github.com/eclipse-ee4j/cdi/issues/472">here goes</a>!</p>

<p>Note that the deprecated removed APIs all have a replacement. Therefore, no functionality is lost even though you might need to change your application accordingly. Below is a list of removals along with their suggested replacements.</p>

<ul>
  <li><code class="language-plaintext highlighter-rouge">@New</code> qualifier
    <ul>
      <li>Replaced by <code class="language-plaintext highlighter-rouge">@Dependent</code> beans since CDI 1.1</li>
    </ul>
  </li>
  <li><code class="language-plaintext highlighter-rouge">Bean#isNullable()</code> method
    <ul>
      <li>Related to the above</li>
      <li>It is safe to just remove this method from any custom implementation of Bean<T> interface as it wasn’t used</T></li>
    </ul>
  </li>
  <li><code class="language-plaintext highlighter-rouge">BeanManager#fireEvent()</code> method
    <ul>
      <li>Deprecated since CDI 2.0; this method was insufficient ever since CDI introduced async events</li>
      <li>Users should use <code class="language-plaintext highlighter-rouge">BeanManager.getEvent()</code> instead</li>
    </ul>
  </li>
  <li><code class="language-plaintext highlighter-rouge">BeanManager#createInjectionTarget(AnnotatedType)</code> method
    <ul>
      <li>Replaced by <code class="language-plaintext highlighter-rouge">BeanManager#getInjectionTargetFactory(AnnotatedType)</code> since CDI 1.1</li>
    </ul>
  </li>
  <li><code class="language-plaintext highlighter-rouge">BeforeBeanDiscovery#addAnnotatedType(AnnotatedType)</code> method
    <ul>
      <li>Replaced by <code class="language-plaintext highlighter-rouge">BeforeBeanDiscovery#addAnnotatedType(AnnotatedType, String)</code> since CDI 1.1</li>
    </ul>
  </li>
  <li>Removed the notion of a mandatory configuration switch for all containers to support different understanding of missing <code class="language-plaintext highlighter-rouge">beans.xml</code> file
    <ul>
      <li>Refers to the <a href="https://jakarta.ee/specifications/cdi/3.0/jakarta-cdi-spec-3.0.html#bean_archive">following specification sentence</a>:</li>
      <li><em>For compatibility with Contexts and Dependency 1.0, products must contain an option to cause an archive to be ignored by the container when no beans.xml is present</em>.</li>
      <li>The behavioral change exists since CDI 1.1</li>
    </ul>
  </li>
</ul>

<h2 id="quality-of-life-improvements">Quality of Life Improvements</h2>

<p>This chapter summarizes some of the minor changes and additions to the specification which won’t make or break your application but can, hopefully, make your life easier.</p>

<h3 id="observable-container-state-events">Observable Container State Events</h3>

<p>Up until now, the only way to know that a CDI container has started was to listen for an event with qualifier <code class="language-plaintext highlighter-rouge">@Initialized(ApplicationScoped.class)</code>. However, this event <a href="https://github.com/eclipse-ee4j/cdi/issues/496">isn’t a true container state event</a>; it is a context-related event. Not to mention that in build oriented stacks, contexts can be started prior to runtime making this event useless. Similarly, container shutdown only has <code class="language-plaintext highlighter-rouge">@BeforeDestroyed(ApplicationScoped.class)</code> which was the closest call but not quite on the mark.
Therefore, CDI 4.0 will fire an event with payload <code class="language-plaintext highlighter-rouge">jakarta.enterprise.event.Startup</code> and qualifier <code class="language-plaintext highlighter-rouge">@Any</code> during container startup. Users and integrators can declare observers in order to perform their early initialization tasks as soon as the CDI container is truly ready. Symmetrically, the container will fire an event with payload <code class="language-plaintext highlighter-rouge">jakarta.enterprise.event.Shutdown</code> and qualifier <code class="language-plaintext highlighter-rouge">@Any</code> during application shutdown.</p>

<p>Observers are encouraged to declare <code class="language-plaintext highlighter-rouge">@Priority</code> in a similar fashion that interceptors do - this enables ordering scheme in which, for example, integrator-defined observer methods for <code class="language-plaintext highlighter-rouge">Startup</code> event precede those defined by user application.</p>

<h3 id="programmatic-lookup-improvements">Programmatic Lookup Improvements</h3>

<p>One of the pitfalls of programmatic lookup is that there is no easy way to browse bean metadata. Besides, iterating over all bean candidates immediately creates bean instances of all <code class="language-plaintext highlighter-rouge">@Dependent</code> beans which isn’t ideal.</p>

<p>These were the main motivations behind <a href="https://github.com/eclipse-ee4j/cdi/issues/521">introduction of the <code class="language-plaintext highlighter-rouge">Handle&lt;T&gt;</code> interface</a> - an abstraction representing a contextual reference handle and allowing browsing its <code class="language-plaintext highlighter-rouge">Bean&lt;T&gt;</code> metadata, retrieving contextual instance and destroying it if needed.</p>

<p>Handles can be grabbed directly from <code class="language-plaintext highlighter-rouge">Instance&lt;T&gt;</code> through several methods:</p>

<ul>
  <li><code class="language-plaintext highlighter-rouge">Handle&lt;T&gt; getHandle()</code></li>
  <li><code class="language-plaintext highlighter-rouge">Iterable&lt;Handle&lt;T&gt;&gt; handles()</code></li>
  <li><code class="language-plaintext highlighter-rouge">Stream&lt;Handle&lt;T&gt;&gt; handlesStream()</code></li>
</ul>

<h3 id="using-priority-on-stereotypes">Using <code class="language-plaintext highlighter-rouge">@Priority</code> on Stereotypes</h3>

<p>Another small change is that <a href="https://github.com/eclipse-ee4j/cdi/issues/495">CDI Stereotypes can now declare <code class="language-plaintext highlighter-rouge">@Priority</code></a>; any bean declaring such stereotype will be considered enabled and have given priority. A bean can declare priority explicitly in order to override the value.</p>

<p>This is a nice shorthand for test scenarios which commonly need to declare enabled alternatives which mock or stub application behavior.</p>

<h2 id="conclusion">Conclusion</h2>

<p>CDI 4.0 specification is nearing its completion and this article should provide you with an overview of changes and how to prepare for them. While a Beta or CR release will hopefully happen shortly, there is always the option to go over to <a href="https://github.com/eclipse-ee4j/cdi">CDI GH repository</a>, check out the main branch and build it with a good old <code class="language-plaintext highlighter-rouge">mvn clean install</code>.</p>

<p>Last but not least, a compatible implementation for CDI Full will still be Weld which is now being worked on to stay on top of CDI API changes. As soon as CDI releases a Beta version, Weld will follow with its own release. So stay tuned if you want to try things out early!</p>]]></content><author><name>matn</name></author><category term="release" /><summary type="html"><![CDATA[As you probably know, work is well under way for projects aiming to land in Jakarta EE 10 space and CDI is no exception. In fact, the specification is close to being rounded up for its next major release hence it is the right time to summarize what is coming.]]></summary></entry></feed>