Skip to content

Commit

Permalink
document generic synthetic bean creation
Browse files Browse the repository at this point in the history
  • Loading branch information
rmanibus committed Sep 5, 2024
1 parent 80190e8 commit 75697ff
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions docs/src/main/asciidoc/cdi-integration.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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<Bar>`.

.`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 <<writing-extensions.adoc#bootstrap-three-phases,Three Phases of Bootstrap and Quarkus Philosophy>> for more information about the difference between `STATIC_INIT` and `RUNTIME_INIT`.

Expand Down

0 comments on commit 75697ff

Please sign in to comment.