|
1 | 1 | package io.quarkus.arc.runtime;
|
2 | 2 |
|
3 | 3 | import java.lang.annotation.Annotation;
|
| 4 | +import java.util.function.Supplier; |
4 | 5 |
|
5 | 6 | import io.quarkus.arc.ManagedContext;
|
6 | 7 |
|
7 | 8 | /**
|
8 | 9 | * Represents a CDI bean container.
|
| 10 | + * <p/> |
| 11 | + * Extensions using this API can also leverage arbitrary methods from running {@link io.quarkus.arc.ArcContainer} |
| 12 | + * which can be obtained by invoking a static method {@link io.quarkus.arc.Arc#container()}. |
9 | 13 | */
|
10 | 14 | public interface BeanContainer {
|
11 | 15 |
|
12 | 16 | /**
|
13 |
| - * Returns a bean instance for given bean type and qualifiers. |
| 17 | + * Resolves a bean instance for given bean type and qualifiers. |
14 | 18 | * <p/>
|
15 |
| - * This method follows standard CDI rules meaning that if there are two or more eligible beans, an ambiguous |
16 |
| - * dependency exception is thrown. |
17 |
| - * Note that the method is allowed to return {@code null} if there is no matching bean which allows |
18 |
| - * for fallback implementations. |
| 19 | + * Performs standard CDI resolution meaning it either returns a bean instance or throws a corresponding exception |
| 20 | + * if the dependency is either unsatisfied or ambiguous. |
19 | 21 | *
|
20 |
| - * @param type |
21 |
| - * @param qualifiers |
22 |
| - * @return a bean instance or {@code null} if no matching bean is found |
| 22 | + * @param beanType type of the bean |
| 23 | + * @param beanQualifiers bean qualifiers |
| 24 | + * @return a bean instance; never {@code null} |
23 | 25 | */
|
24 |
| - default <T> T beanInstance(Class<T> type, Annotation... qualifiers) { |
25 |
| - return beanInstanceFactory(type, qualifiers).create().get(); |
26 |
| - } |
27 |
| - |
28 |
| - /** |
29 |
| - * This method is deprecated and will be removed in future versions. |
30 |
| - * Use {@link #beanInstance(Class, Annotation...)} instead. |
31 |
| - * </p> |
32 |
| - * As opposed to {@link #beanInstance(Class, Annotation...)}, this method does <b>NOT</b> follow CDI |
33 |
| - * resolution rules and in case of ambiguous resolution performs a choice based on the class type parameter. |
34 |
| - * |
35 |
| - * @param type |
36 |
| - * @param qualifiers |
37 |
| - * @return a bean instance or {@code null} if no matching bean is found |
38 |
| - */ |
39 |
| - @Deprecated |
40 |
| - default <T> T instance(Class<T> type, Annotation... qualifiers) { |
41 |
| - return instanceFactory(type, qualifiers).create().get(); |
42 |
| - } |
| 26 | + <T> T beanInstance(Class<T> beanType, Annotation... beanQualifiers); |
43 | 27 |
|
44 | 28 | /**
|
45 | 29 | * Returns an instance factory for given bean type and qualifiers.
|
46 | 30 | * <p/>
|
47 |
| - * This method follows standard CDI rules meaning that if there are two or more beans, an ambiguous dependency |
48 |
| - * exception is thrown. |
49 |
| - * Note that the factory itself is still allowed to return {@code null} if there is no matching bean which allows |
50 |
| - * for fallback implementations. |
| 31 | + * This method performs CDI ambiguous dependency resolution and throws and exception if there are two or more beans |
| 32 | + * with given type and qualifiers. |
| 33 | + * <p/> |
| 34 | + * If no matching bean is found, uses a default fallback factory that will attempt to instantiate a non-CDI object |
| 35 | + * of the given class via no-args constructor. |
| 36 | + * <p/> |
| 37 | + * If you need custom factory behavior, take a look at {@link #beanInstanceFactory(Supplier, Class, Annotation...)} |
51 | 38 | *
|
52 |
| - * @param type |
53 |
| - * @param qualifiers |
| 39 | + * @param type bean type |
| 40 | + * @param qualifiers bean qualifiers |
54 | 41 | * @return a bean instance factory, never {@code null}
|
55 | 42 | */
|
56 | 43 | <T> Factory<T> beanInstanceFactory(Class<T> type, Annotation... qualifiers);
|
57 | 44 |
|
58 | 45 | /**
|
59 |
| - * This method is deprecated and will be removed in future versions. |
60 |
| - * Use {@link #beanInstanceFactory(Class, Annotation...)} instead. |
61 |
| - * </p> |
62 |
| - * As opposed to {@link #beanInstanceFactory(Class, Annotation...)}, this method does <b>NOT</b> follow CDI |
63 |
| - * resolution rules and in case of ambiguous resolution performs a choice based on the class type parameter. |
| 46 | + * Returns an instance factory for given bean type and qualifiers. |
| 47 | + * <p/> |
| 48 | + * This method performs CDI ambiguous dependency resolution and throws and exception if there are two or more beans |
| 49 | + * with given type and qualifiers. |
| 50 | + * <p/> |
| 51 | + * If no matching bean is found, delegates all calls to the supplied factory fallback. |
64 | 52 | *
|
65 |
| - * @param type |
66 |
| - * @param qualifiers |
| 53 | + * @param fallbackSupplier supplier to delegate to if there is no bean |
| 54 | + * @param type bean type |
| 55 | + * @param qualifiers bean qualifiers |
67 | 56 | * @return a bean instance factory, never {@code null}
|
68 | 57 | */
|
69 |
| - @Deprecated |
70 |
| - <T> Factory<T> instanceFactory(Class<T> type, Annotation... qualifiers); |
| 58 | + <T> Factory<T> beanInstanceFactory(Supplier<Factory<T>> fallbackSupplier, Class<T> type, |
| 59 | + Annotation... qualifiers); |
71 | 60 |
|
72 | 61 | /**
|
73 | 62 | * <pre>
|
|
0 commit comments