I am trying to access Coldbox getSetting
within a model.
In the docs, and on Coldbox Google Group posts, it clearly states
The model is a completely isolated layer of your application and has no access to anything ColdBox unless you inject dependencies into them. We suggest you look at our WireBox dependency injection so you can see how to inject the models with what they need.
They point to this doc: http://wiki.coldbox.org/wiki/WireBox.cfm#The_WireBox_Injector
But other than the somewhat confusing doc and Google Group posts repeating that quote above, there is no real good example on how to do it.
I have attempted property injection at the top of my model:
<cfcomponent displayname="myComponent" output="false">
<cfproperty name="mySetting" inject="coldbox:setting:mySetting" />
<cffunction name="myFunction" output="false" hint="index">
<cfset value = getProperty('mySetting') />
...
This returns Error Messages: Variable GETPROPERTY is undefined.
I also attempted an argument injection in the function of my model, but I knew that wouldn't work.
<cffunction name="myFunction" output="false" hint="index">
<cfargument name="mySetting" inject="coldbox:setting:mySetting">
Can anyone show me how to pass getSetting
to a model via wirebox injection, or really any method?
How do you inject a dependency in the model of Coldbox?
Your injection looks fine. The issue is that you are trying to use "getProperty()" which is not defined in your component. It comes from the framework supertype and only exists in frameworks objects like handlers, etc. Property injection places the reference to the injected object directly into the "variables" scope by default, so you just access it as variables.mySetting.
You can also control the scope that the property is injected into with the scope attribute:
http://wiki.coldbox.org/wiki/WireBox.cfm#Property_Annotation
Argument injection DOES work, but only for constructors (init) since they are called automatically by the DI engine.
Also, this ref card may be a bit simpler to read through than the full WireBox docs, but it obviously doesn't cover as much information: https://github.com/ColdBox/cbox-refcards/raw/master/WireBox/WireBox-Refcard.pdf
Disclaimer: I am part of Team ColdBox.