public interface ObjectProvider<T> extends ObjectFactory<T>
ObjectFactory
designed specifically for injection points,
allowing for programmatic optionality and lenient not-unique handling.Modifier and Type | Method and Description |
---|---|
T |
getIfAvailable()
Return an instance (possibly shared or independent) of the object
managed by this factory.
|
default T |
getIfAvailable(Supplier<T> defaultSupplier)
Return an instance (possibly shared or independent) of the object
managed by this factory.
|
T |
getIfUnique()
Return an instance (possibly shared or independent) of the object
managed by this factory.
|
default T |
getIfUnique(Supplier<T> defaultSupplier)
Return an instance (possibly shared or independent) of the object
managed by this factory.
|
T |
getObject(Object... args)
Return an instance (possibly shared or independent) of the object
managed by this factory.
|
default void |
ifAvailable(Consumer<T> dependencyConsumer)
Consume an instance (possibly shared or independent) of the object
managed by this factory, if available.
|
default void |
ifUnique(Consumer<T> dependencyConsumer)
Consume an instance (possibly shared or independent) of the object
managed by this factory, if unique.
|
getObject
T getObject(Object... args) throws BeansException
Allows for specifying explicit construction arguments, along the
lines of BeanFactory.getBean(String, Object...)
.
args
- arguments to use when creating a corresponding instanceBeansException
- in case of creation errorsObjectFactory.getObject()
@Nullable T getIfAvailable() throws BeansException
null
if not availableBeansException
- in case of creation errorsObjectFactory.getObject()
default T getIfAvailable(Supplier<T> defaultSupplier) throws BeansException
defaultSupplier
- a callback for supplying a default object
if none is present in the factoryBeansException
- in case of creation errorsgetIfAvailable()
default void ifAvailable(Consumer<T> dependencyConsumer) throws BeansException
dependencyConsumer
- a callback for processing the target object
if available (not called otherwise)BeansException
- in case of creation errorsgetIfAvailable()
@Nullable T getIfUnique() throws BeansException
null
if not available or
not unique (i.e. multiple candidates found with none marked as primary)BeansException
- in case of creation errorsObjectFactory.getObject()
default T getIfUnique(Supplier<T> defaultSupplier) throws BeansException
defaultSupplier
- a callback for supplying a default object
if no unique candidate is present in the factoryBeansException
- in case of creation errorsgetIfUnique()
default void ifUnique(Consumer<T> dependencyConsumer) throws BeansException
dependencyConsumer
- a callback for processing the target object
if unique (not called otherwise)BeansException
- in case of creation errorsgetIfAvailable()