Boost is a framework for working with Java. This page describes how to use the IoC part of Boost called Spider with Groovy.
Spider has a very interface oriented view of the world. If you are into Interface oriented design (e.g. Ken Pugh's book) and use fine-grained interfaces, you will feel right at home. So first, let's create a Java interface:
...
| Code Block |
|---|
package foo import au.net.netstorm.boost.spider.ioc.BoostWeb import au.net.netstorm.boost.spider.api.entry.DefaultEntrySpiderMain def entrymain = new DefaultEntrySpiderMain(BoostWeb) entrymain.gomain(PleaseDontGo) |
Here, BoostWeb provides some nice defaults for us to use. Running this gives:
...
We can also override the Web. For instance, we can supply our own web:
| Code Block |
|---|
package foo import au.net.netstorm.boost.spider.api.config.web.Web import au.net.netstorm.boost.spider.api.config.bindingswire.BinderWire class TangledWeb implements Web { @PackageScope BinderWire binderwire void web() { binderwire.bindref(MeTwo).to({ println 'Reporting stuff2' } as MeTwo).to(MeTwo) } } |
Which tells the IoC framework to use the supplied closure whenever it needs to inject a MeTwo implementation. Note again the use of the PackageScope AST macro to override Groovy's default property behavior. With this in place, our main script becomes:
| Code Block |
|---|
def entrymain = new DefaultEntrySpiderMain(BoostWeb, TangledWeb) entrymain.gomain(PleaseDontGo) |
And the output will be:
...