spring-framework / org.springframework.beans.factory / ObjectProvider

ObjectProvider

interface ObjectProvider<T : Any> : ObjectFactory<T>

A variant of ObjectFactory designed specifically for injection points, allowing for programmatic optionality and lenient not-unique handling.

Author
Juergen Hoeller

Since
4.3

Functions

getIfAvailable

abstract fun getIfAvailable(): T
open fun getIfAvailable(defaultSupplier: Supplier<T>): T

Return an instance (possibly shared or independent) of the object managed by this factory.

getIfUnique

abstract fun getIfUnique(): T
open fun getIfUnique(defaultSupplier: Supplier<T>): T

Return an instance (possibly shared or independent) of the object managed by this factory.

getObject

abstract fun getObject(vararg args: Any): T

Return an instance (possibly shared or independent) of the object managed by this factory.

Allows for specifying explicit construction arguments, along the lines of BeanFactory#getBean(String, Object...).

ifAvailable

open fun ifAvailable(dependencyConsumer: Consumer<T>): Unit

Consume an instance (possibly shared or independent) of the object managed by this factory, if available.

ifUnique

open fun ifUnique(dependencyConsumer: Consumer<T>): Unit

Consume an instance (possibly shared or independent) of the object managed by this factory, if unique.