Skip to content

Commit

Permalink
Merge pull request #42948 from rmanibus/generic_synthetic_beans_doc
Browse files Browse the repository at this point in the history
Document generic synthetic bean creation
  • Loading branch information
mkouba authored Sep 5, 2024
2 parents bd33359 + 75697ff commit 0ca50ae
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 0ca50ae

Please sign in to comment.