Hello there…
I am attempting to implement WireBox into my machii application.
I have my WireBox injector up and running along side my WireBox Binder configuration.
This all makes sense in relation to model layer components such as Service,DAO etc.
But in my Listener components I am unsure what is the best method to inject dependencies.
I cannot seem to do it in the same way it is accomplished when using a Service
Posted bfreo i had finished… try again
Hello there…
I am attempting to implement WireBox into my machii application.
I have my WireBox injector up and running along side my WireBox Binder configuration.
This all makes sense in relation to model layer components such as Service,DAO etc.
But in my Listener components I am unsure what is the best method to inject dependencies.
I cannot seem to do it in the same way it is accomplished when using a Service
For example
map(“feedService”).to(“coldbox.samples.applications.ColdBoxReader.components.services.feedService”)
.initArg(name=“feedDAO”,ref=“feedDAO”)
.initArg(name=“ModelBasePath”,value=getProperty(‘ModelBasePath’))
.initArg(name=“feedReader”,ref=“feedReader”)
.asSingleton();
This is because there is no init method in my MachII listener… Only a configure method…
So what is the best way to inject into a Machii Listener?
thanks
bdw429s
November 29, 2013, 4:21pm
3
Have you tried setter injection or mixin injection? I don’t know much about MachII, but IF WireBox is creating the listenter, you can just put properties at the top of it and your dependencies will be autowired in for you. We show how properties work in our WireBox Ref Card: https://github.com/ColdBox/cbox-refcards/raw/master/WireBox/WireBox-Refcard.pdf
If you prefer to do it all in your config, you should be able to do map().to().property() to add the properties you want injected.
http://wiki.coldbox.org/wiki/WireBox.cfm#Dependencies_DSL
map("AbstractService").to("model.AbstractService");
.property(name:"someAlphaDAO", ref:"someAlphaDAO")
.property(name:"someBravoDAO", ref:"someBravoDAO");
If WireBox does not create the listener, you can still use the amazing power of WireBox to autowire it. Just call wirebox.autowire(object) sometime after it’s created. In fact, the configure method could just do application.wirebox.autowire(this).
Thanks!
~Brad
ColdBox Platform Evangelist
Ortus Solutions, Corp
E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com
Thanks very much for your help!!
Unfortunately Machii instantiates our listeners… but these are part of our implementation anyway so no big deal putting in more implementation code in.
I think the autowiring sounds the neatest way of doing this!
thanks!
Having a bit of trouble getting this working
in my WireBox binding cfc I have the following map setup
map(“UtilityService”).to(“epsys.model.UtilityService”)
.asSingleton()
;
I have set this up as a property in one of my listeners as a property.
Then in my configure method within my listener I run the autowire
application.wirebox.autowire(this);
I then attempt to get the property UtillityService… But its just an empty string!
writeDump(this.getProperty(‘UtilityService’));
abort;
Any ideas would be appreciated… thanks!
Aaron
December 2, 2013, 5:29pm
6
try inject=“model:utilityService”;
What do you get if you just dump variables.UtilityService?
Thanks!
~Brad
ColdBox Platform Evangelist
Ortus Solutions, Corp
E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com