Model-Glue 3 "Beans" Injection
One of my favorite features in Model-Glue, suggested and originally implemented by Sean Corfield, is autowiring. With autowiring, if you create a method named setSomeService() on a Controller, the framework will automatically search a ColdSpring bean factory for a bean named "someService" and set it into the controller.
It's super-cool, but it requires some explicit, repetitive code: writing nearly identical setters on your controller for the services it needs.
Model-Glue 3's code name is "Gesture," and it stands for declarative workflows and elimination of boilerplate. Clearly, something had to be done about all these setters that just serve as a marker for autowiring.
In Model-Glue 3, this "something" is a new attribute on the <controller /> tag called "beans":
id="contactController"
type="com.myapp.controller.ContactController"
beans="contactService,authenticationService"
/>
Inside of each Model-Glue controller is a new scope called "beans" (really, it's just a struct in variables....). When the framework loads, it automagically sets any beans listed in the "beans" attribute of <controller /> into the "beans" scope, keyed by beanId, no setter required.
In other words, as soon as I reload the framework with the above <controller /> tag, I can do this in any listener function:
Fun stuff!


More configuration please! Excellent work!
getModelGlue().getBean("myBean") is the "classic" pre-autowiring way of doing it, and is available in all public versions of model-glue.
Is that what you're after?
@Mark,
Glad you like! It's the first of three or four new features that are in this vein.
I realize now that what I'm looking for is to have the getSomeBean() method automatically generated in the controller, and I suppose that may not be possible (or worthwhile). I just figured that if you are removing the requirement to define the setSomeBean() function it would be great to not have to define the getSomeBean() function either, but still have access to it.
Would there be a way of doing that, or is that just pie-in-the-sky?
DW
Ah, Ok, I see what you're saying now: generate the getSomeService() method when it's first called.
I thought about having a CF8-only feature that used onMissingMethod to do this, but I wanted to:
1. Keep the functionality consistent across versions
2. Not make pre-emptive use of onMissingMethod: something else may come up in the future where I'd kick myself for reserving it for autowiring purposes.