|
16 | 16 |
|
17 | 17 | package org.springframework.context.support |
18 | 18 |
|
| 19 | +import org.springframework.beans.factory.ObjectProvider |
19 | 20 | import org.springframework.beans.factory.config.BeanDefinition |
20 | 21 | import org.springframework.beans.factory.config.BeanDefinitionCustomizer |
| 22 | +import org.springframework.beans.factory.getBeanProvider |
21 | 23 | import org.springframework.beans.factory.support.BeanDefinitionReaderUtils |
22 | 24 | import org.springframework.context.ApplicationContextInitializer |
23 | 25 | import org.springframework.core.env.ConfigurableEnvironment |
@@ -81,10 +83,10 @@ open class BeanDefinitionDsl(private val init: BeanDefinitionDsl.() -> Unit, |
81 | 83 | internal val children = arrayListOf<BeanDefinitionDsl>() |
82 | 84 |
|
83 | 85 | /** |
84 | | - * Access to the context for advanced use-cases. |
85 | | - * @since 5.1 |
| 86 | + * @see provider |
86 | 87 | */ |
87 | | - lateinit var context: GenericApplicationContext |
| 88 | + @PublishedApi |
| 89 | + internal lateinit var context: GenericApplicationContext |
88 | 90 |
|
89 | 91 | /** |
90 | 92 | * Shortcut for `context.environment` |
@@ -245,6 +247,15 @@ open class BeanDefinitionDsl(private val init: BeanDefinitionDsl.() -> Unit, |
245 | 247 | else -> context.getBean(name, T::class.java) |
246 | 248 | } |
247 | 249 |
|
| 250 | + |
| 251 | + /** |
| 252 | + * Return an provider for the specified bean, allowing for lazy on-demand retrieval |
| 253 | + * of instances, including availability and uniqueness options. |
| 254 | + * @since 5.1.1 |
| 255 | + * @see org.springframework.beans.factory.BeanFactory.getBeanProvider |
| 256 | + */ |
| 257 | + inline fun <reified T : Any> provider() : ObjectProvider<T> = context.getBeanProvider() |
| 258 | + |
248 | 259 | /** |
249 | 260 | * Take in account bean definitions enclosed in the provided lambda only when the |
250 | 261 | * specified profile is active. |
|
0 commit comments