From a6d1cd3d637645d89a15e5ceb134354c425fda0b Mon Sep 17 00:00:00 2001 From: David Mueller Date: Fri, 13 Sep 2024 11:26:14 -0400 Subject: [PATCH 1/2] Update cdi-extension-user-feature.adoc --- .../pages/cdi-extension-user-feature.adoc | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/modules/ROOT/pages/cdi-extension-user-feature.adoc b/modules/ROOT/pages/cdi-extension-user-feature.adoc index e8102762e..f3059db79 100644 --- a/modules/ROOT/pages/cdi-extension-user-feature.adoc +++ b/modules/ROOT/pages/cdi-extension-user-feature.adoc @@ -11,9 +11,9 @@ :seo-description: :page-layout: general-reference :page-type: general -= Creating a CDI Extension inside a User Feature += Creating a CDI extension inside an Open Liberty user feature -Contexts and Dependency Injection (CDI) provides powerful extensions to augment, extend, or override the behaviour of CDI. If you wish for the extensions inside a Open Liberty User Feature to be found by CDI you must implement an Open Liberty specific SPI: `io.openliberty.cdi.spi.CDIExtensionMetadata`. +Contexts and Dependency Injection (CDI) provides powerful extensions to augment, extend, or override the behavior of CDI. To enable CDI to find the extensions inside an Open Liberty user feature, you must implement an Open Liberty-specific SPI: `io.openliberty.cdi.spi.CDIExtensionMetadata`. `CDIExtensionMetadata` also provides syntactic sugar for the two most common uses of a CDI Extension: Registering a class as a CDI bean, and registering an annotation as a Bean Defining Annotation (BDA). @@ -39,19 +39,19 @@ public class CDIIntegrationMetaData implements CDIExtensionMetadata //CDIBean will become a CDI bean and can be injected with `@Inject CDIBean cdiBean`. If it does not have a scope, the scope will default to @Dependent. return Set.of(CDIBean.class); } - + public Set> getBeanDefiningAnnotationClasses() { - //CDIAnnotation will become a BeanDefiningAnnotation. Any class annotated @Annotation can be injected via CDI. - //Unless CDIAnnotation defines otherwise, the default scope is @Dependent. See https://jakarta.ee/specifications/cdi/4.0/jakarta-cdi-spec-4.0#scopes + //CDIAnnotation will become a BeanDefiningAnnotation. Any class annotated @Annotation can be injected via CDI. + //Unless CDIAnnotation defines otherwise, the default scope is @Dependent. See https://jakarta.ee/specifications/cdi/4.0/jakarta-cdi-spec-4.0#scopes //For details on how annotations define their scope. return Set.of(CDIAnnotation.class); } - + public Set> getExtensions() { - //CDIExtension will be processed as a full CDI extension. + //CDIExtension will be processed as a full CDI extension. return Set.of(CDIExtension.class); } - + } ---- @@ -60,8 +60,7 @@ The `@Component` annotation is required so that Open Liberty will process your i And this is all you need to make your user extension extend CDI. If you want a step by step guide to creating a user feature that extends CDI from scratch see the link below. -= Useful Links +== See also Javadoc for `CDIExtensionMetadata` can be found at: https://openliberty.io/docs/latest/reference/javadoc/spi/cdi-1.2.html?path=24.0.0.8/com.ibm.websphere.appserver.spi.cdi_1.1-javadoc/io/openliberty/cdi/spi/package-summary.html A step by step guide to creating a user feature, including an implementation of `CDIExtensionMetadata`, can be found at: https://openliberty.io/blog/2024/06/28/liberty-user-feature-tutorial.html - From 97d020b4955db7ab3583a3937334a1398c288701 Mon Sep 17 00:00:00 2001 From: David Mueller Date: Fri, 13 Sep 2024 15:32:40 -0400 Subject: [PATCH 2/2] edits #7531 --- .../pages/cdi-extension-user-feature.adoc | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/modules/ROOT/pages/cdi-extension-user-feature.adoc b/modules/ROOT/pages/cdi-extension-user-feature.adoc index f3059db79..578d8a143 100644 --- a/modules/ROOT/pages/cdi-extension-user-feature.adoc +++ b/modules/ROOT/pages/cdi-extension-user-feature.adoc @@ -15,9 +15,10 @@ Contexts and Dependency Injection (CDI) provides powerful extensions to augment, extend, or override the behavior of CDI. To enable CDI to find the extensions inside an Open Liberty user feature, you must implement an Open Liberty-specific SPI: `io.openliberty.cdi.spi.CDIExtensionMetadata`. -`CDIExtensionMetadata` also provides syntactic sugar for the two most common uses of a CDI Extension: Registering a class as a CDI bean, and registering an annotation as a Bean Defining Annotation (BDA). +The `CDIExtensionMetadata` class also enables the two most common uses of a CDI Extension: registering a class as a CDI bean, and registering an annotation as a bean defining annotation (BDA). -Here is an example of an implementation of `CDIExtensionMetadata`. +The following example shows an implementation of the `CDIExtensionMetadata` class, with three possible methods that extend the class: `getBeanClasses`, `getBeanDefiningAnnotationClasses`, and `getExtensions`. +Each of these methods has a default implementation that returns an empty set, so you can implement only the ones that are relevant to your needs. [source,java] @@ -36,31 +37,31 @@ import org.osgi.service.component.annotations.Component; public class CDIIntegrationMetaData implements CDIExtensionMetadata { public Set> getBeanClasses() { - //CDIBean will become a CDI bean and can be injected with `@Inject CDIBean cdiBean`. If it does not have a scope, the scope will default to @Dependent. + //CDIBean becomes a CDI bean and can be injected with `@Inject CDIBean cdiBean`. If it does not have a scope, the scope defaults to @Dependent. return Set.of(CDIBean.class); } public Set> getBeanDefiningAnnotationClasses() { - //CDIAnnotation will become a BeanDefiningAnnotation. Any class annotated @Annotation can be injected via CDI. + //CDIAnnotation becomes a BeanDefiningAnnotation. Any class annotated @Annotation can be injected via CDI. //Unless CDIAnnotation defines otherwise, the default scope is @Dependent. See https://jakarta.ee/specifications/cdi/4.0/jakarta-cdi-spec-4.0#scopes //For details on how annotations define their scope. return Set.of(CDIAnnotation.class); } public Set> getExtensions() { - //CDIExtension will be processed as a full CDI extension. + //CDIExtension is processed as a full CDI extension. return Set.of(CDIExtension.class); } } ---- -The `@Component` annotation is required so that Open Liberty will process your implementation of CDIExtensionMetadata. The three methods all have a default implementation that returns an empty set, so you only have to implement the ones relevent to your needs. +The `@Component` annotation is required so that Open Liberty processes your implementation of the `CDIExtensionMetadata` class. -And this is all you need to make your user extension extend CDI. If you want a step by step guide to creating a user feature that extends CDI from scratch see the link below. +This configuration is all you need to make your user extension extend CDI. For a step-by-step guide to creating a user feature that extends CDI, see the link:https://openliberty.io/blog/2024/06/28/liberty-user-feature-tutorial.html[How to package a library as an Open Liberty user feature] blog post. == See also -Javadoc for `CDIExtensionMetadata` can be found at: https://openliberty.io/docs/latest/reference/javadoc/spi/cdi-1.2.html?path=24.0.0.8/com.ibm.websphere.appserver.spi.cdi_1.1-javadoc/io/openliberty/cdi/spi/package-summary.html +- link:https://openliberty.io/docs/latest/reference/javadoc/spi/cdi-1.2.html?path=24.0.0.8/com.ibm.websphere.appserver.spi.cdi_1.1-javadoc/io/openliberty/cdi/spi/package-summary.html[CDIExtensionMetadata Javadoc] -A step by step guide to creating a user feature, including an implementation of `CDIExtensionMetadata`, can be found at: https://openliberty.io/blog/2024/06/28/liberty-user-feature-tutorial.html +- link:https://jakarta.ee/specifications/cdi/4.0/jakarta-cdi-spec-4.0#scopes[Scopes in CDI 4.0]