3.4 Injectable Container Types
In addition to being able to inject beans Micronaut natively supports injecting the following types:
Table 1. Injectable Container Types Type | Description | Example |
---|
java.util.Optional | An Optional of a bean. If the bean doesn’t exist empty() is injected | Optional<Engine>
|
java.lang.Iterable | An Iterable or subtype of Iterable (example List , Collection etc.) | Iterable<Engine>
|
java.util.stream.Stream | A lazy Stream of beans | Stream<Engine>
|
Array | A native array of beans of a given type | Engine[]
|
Provider | A javax.inject.Provider if a circular dependency requires it or to instantiate a prototype for each get call. | Provider<Engine>
|
| A prototype bean will have one instance created per place the bean is injected. When a prototype bean is injected as a Provider , each call to get() will create a new instance. |