Does Wirebox autowire by name like ColdSpring?

In Coldspring, if I have bean ServiceA and ServiceB and ServiceC has
setters for both ServiceA and ServiceB, with default-
autowire="byName", I don't have to even annotate anything in ServiceC.

Does Wirebox has something similar? or must I use inject="ServiceA",
inject="ServiceB" in ServiceC.cfc?

Thanks.

You need the property but not inject="" if you are wiring by name.

Jason Durham

Oh wirebox does that automatically? or has to be turned on in config
somewhere?

Thx,
Henry

Henry, you only need to switch WireBox on.

Regards,
Andrew Scott
http://www.andyscott.id.au/

I just tested it out today, without inject="id:BeanName" it doesn't
inject automatically by name. Or did I miss some config?

Thx,
Henry

You are talking about setters right?

Luis F. Majano
President
Ortus Solutions, Corp
www.ortussolutions.com

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Social: twitter.com/lmajano facebook.com/lmajano

With XML attribute ‘default-autowire=“byName”’, ColdSpring will inspect all setters and inject setter that matches with bean id automatically.

If I’m not mistaken, Wirebox only support inject=“id:beanID” or explicitly specified in config/wirebox.cfc.

Henry

Ok, so let’s say you had this in CS

function setService(service){}

You have three choices with WireBox:

  1. Keep the source the same and configure via binder:
    map(“Service”).setter(name=“service”,ref=“service”)

  2. Add to the source either below:
    function setService(service) inject{}
    function setService(service) inject=“id”{}
    function setService(service) inject=“id:alias”{}

  3. Create a listener that listens to: afterInstanceInspection
    You will receive there the mapping evaluated, the binder and the injector. Then you can do something like this

Get the object’s metadata from the mapping: mapping.getObjectMetadata()
Then iterate the functions on it and add all methods that start with “set”
if( left(md.functions[x].name,3){
mapping.addSetter(name=right(md.functions[x].name, Len(md.functions[x].name)-3),dsl=“id”);
}

The compromise in WireBox is that we do not want to just go with any method that starts with “set” for DI evaluations. There is performance issues with it and also warnings when matching methods that just start with the letters “set” but not really a setter.

The third approach is the most elegant if you ask me because then this could be your ColdSpring setter compatibility listener. Just add the listener and the autowire behavior will be the same as ColdSpring for setters.

Luis F. Majano
President
Ortus Solutions, Corp
www.ortussolutions.com

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Social: twitter.com/lmajano facebook.com/lmajano