| 1 |
/* |
| 2 |
* Copyright (c) 2021 Red Hat and others |
| 3 |
* |
| 4 |
* This program and the accompanying materials are made available under the |
| 5 |
* Apache Software License 2.0 which is available at: |
| 6 |
* https://www.apache.org/licenses/LICENSE-2.0. |
| 7 |
* |
| 8 |
* SPDX-License-Identifier: Apache-2.0 |
| 9 |
*/ |
| 10 |
|
| 11 |
package jakarta.enterprise.inject.build.compatible.spi; |
| 12 |
|
| 13 |
import jakarta.enterprise.inject.Instance; |
| 14 |
|
| 15 |
/** |
| 16 |
* Creation function for a synthetic bean defined by {@link SyntheticBeanBuilder}. |
| 17 |
* CDI container will create an instance of the creation function every time when it needs |
| 18 |
* to obtain an instance of the synthetic bean. Implementations must be {@code public} |
| 19 |
* classes with a {@code public} zero-parameter constructor; they must not be beans. |
| 20 |
* |
| 21 |
* @param <T> the bean class of the synthetic bean |
| 22 |
* @since 4.0 |
| 23 |
*/ |
| 24 |
public interface SyntheticBeanCreator<T> { |
| 25 |
/** |
| 26 |
* Creates an instance of the synthetic bean. |
| 27 |
* May only return {@code null} if the synthetic bean is {@code @Dependent}. |
| 28 |
* <p> |
| 29 |
* The {@link Instance} parameter may be used to simulate producer method parameter injection. |
| 30 |
* However, {@code @Dependent} bean instances obtained from the {@code Instance} during execution |
| 31 |
* remain managed until the synthetic bean instance is destroyed. Therefore, implementations |
| 32 |
* are encouraged to destroy unneeded {@code @Dependent} bean instances obtained from the {@code Instance}. |
| 33 |
* <p> |
| 34 |
* If the synthetic bean is {@code @Dependent}, the {@code InjectionPoint} to which it is injected |
| 35 |
* may be looked up from the {@code Instance} parameter. |
| 36 |
* <p> |
| 37 |
* The parameter map contains the same values that were passed to the {@link SyntheticBeanBuilder} |
| 38 |
* that defined the synthetic bean. |
| 39 |
* |
| 40 |
* @param lookup an {@link Instance} that can be used to lookup other beans, never {@code null} |
| 41 |
* @param params the parameter map, never {@code null} |
| 42 |
* @return an instance of the bean, may only be {@code null} if the synthetic bean is {@code @Dependent} |
| 43 |
*/ |
| 44 |
T create(Instance<Object> lookup, Parameters params); |
| 45 |
} |