From 98ed7a3b1fe970242def605f5ba889a19bb0a605 Mon Sep 17 00:00:00 2001 From: Loic Hermann Date: Wed, 4 Sep 2024 20:54:24 -0400 Subject: [PATCH] document generic synthetic bean creation --- docs/src/main/asciidoc/cdi-integration.adoc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/docs/src/main/asciidoc/cdi-integration.adoc b/docs/src/main/asciidoc/cdi-integration.adoc index 4c9233e24fce5..39920b6516e60 100644 --- a/docs/src/main/asciidoc/cdi-integration.adoc +++ b/docs/src/main/asciidoc/cdi-integration.adoc @@ -323,6 +323,24 @@ SyntheticBeanBuildItem syntheticBean(TestRecorder recorder) { <1> By default, a synthetic bean is initialized during `STATIC_INIT`. <2> The bean instance is supplied by a value returned from a recorder method. +It is also possible to create a generic synthetic bean `Foo`. + +.`SyntheticBeanBuildItem` Example 3 +[source,java] +---- +@BuildStep +@Record(STATIC_INIT) +SyntheticBeanBuildItem syntheticBean(TestRecorder recorder) { + return SyntheticBeanBuildItem.configure(Foo.class) + .types(ParameterizedType.create(Foo.class, ClassType.create(Bar.class)))) <1> + .scope(Singleton.class) + .runtimeValue(recorder.createFooBar()) + .done(); +} +---- + +<1> `types()` or `addType()` must be used to specify the generic type. + It is possible to mark a synthetic bean to be initialized during `RUNTIME_INIT`. See the <> for more information about the difference between `STATIC_INIT` and `RUNTIME_INIT`.