I'm pleased to annonce a Grails course in Asturias, Spain. The course is organized by the College of Engineers of Principado de Asturias, from 5th to 10th of may, around 15 hours training in Groovy and Grails technologies.
The title of course can be translate as "Agile Development in Java EE with Grails". If any one is interested, can contact to me by mail.
Here the slides (in Spanish) for my first class.
Thursday, 17 April 2008
Monday, 7 April 2008
Grails: Plugglabe Service, Reloaded
Yesterday I've read, the post from Josh Creed about a pluggable service in Grails and I've been thinking the way to do with IoC and wire provider with Spring.
Let's do it, with small test.
First my service class GreetService:
Now, two Providers:
Now I'm gonna use Spring DSL, in resources.groovy, to define provider bean that depends of environment:
And that's all with Groovy and Grails magic, here the test:
And in Grails console, another test:
Let's do it, with small test.
First my service class GreetService:
class GreetService {
def provider
def sayHello(String name){
provider.sayHello(name)
}
}
class DevProvider {
def sayHello(String name){
println "DevProvider: hello ${name}"
}
}
class TestProvider {
def sayHello(String name){
println "TestProvider: hello ${name}"
}
}
import grails.util.*
beans = {
switch(GrailsUtil.environment) {
case "test":
provider(TestProvider)
break
case "development":
provider(DevProvider)
break
}
}
class GreetServiceTests extends GroovyTestCase {
def greetService
void testGreet() {
greetService.sayHello("World!!!!!!")
}
}
// output: TestProvider: hello World!!!!!!
def service = ctx.getBean("greetService")
service.sayHello("world")
// output: DevProvider: hello world
Subscribe to:
Posts (Atom)