Avoid requiring it parameter in Kotlin bean DSL

By using function literals with receiver, we can avoid requiring
lambda parameters for a shorter and nicer syntax. Based on a
proposal from Joseph Taylor.

Issue: SPR-15815
This commit is contained in:
Sebastien Deleuze
2017-07-25 11:18:52 +02:00
parent d7a7b08b08
commit 29c112c010
2 changed files with 10 additions and 10 deletions

View File

@@ -32,8 +32,8 @@ class BeanDefinitionDslTests {
val beans = beans {
bean<Foo>()
bean<Bar>("bar", scope = Scope.PROTOTYPE)
bean { Baz(it.ref<Bar>()) }
bean { Baz(it.ref("bar")) }
bean { Baz(ref()) }
bean { Baz(ref("bar")) }
}
val context = GenericApplicationContext()
@@ -55,8 +55,8 @@ class BeanDefinitionDslTests {
profile("pp") {
bean<Foo>()
}
bean { Baz(it.ref<Bar>()) }
bean { Baz(it.ref("bar")) }
bean { Baz(ref()) }
bean { Baz(ref("bar")) }
}
}
@@ -78,10 +78,10 @@ class BeanDefinitionDslTests {
val beans = beans {
bean<Foo>()
bean<Bar>("bar")
bean { FooFoo(it.env["name"]) }
environment({it.activeProfiles.contains("baz")}) {
bean { Baz(it.ref()) }
bean { Baz(it.ref("bar")) }
bean { FooFoo(env["name"]) }
environment( { activeProfiles.contains("baz") } ) {
bean { Baz(ref()) }
bean { Baz(ref("bar")) }
}
}