Hello! I'm working on a .cfc file on my coldbox se...
# box-products
j
Hello! I'm working on a .cfc file on my coldbox server that is not stored in the models or handlers folder of my server. Is it still possible to instantiate objects from modules there, like logbox, for example? I'm used to just performing injections like
Copy code
property name="logger"      inject="logbox:root"
However, I don't believe I have access to injection syntax like this outside of my models or handlers folders.
p
In wirebox you can initiate by adding a
mapDirectory()
so it can pick up
In your config/wirebox.cfc file
j
Oh awesome! Didn't know I could do that. Thank you!
👍🏻 1
So since I'm in Coldbox, I think the framework is setting up wirebox behind the curtain. Is there a particular location in my app where I should should run the
mapDirectory()
function so it can pick up the desired directory?
p
You add that to your
config/wirebox.cfc
file in the coldbox app,
🙌 1
j
Okay! I apologize for not doublechecking your earlier message.
p
No problem; then you also need to reinit or restart your app.
j
So I have mapped these directories in my Wirebox.cfc file. Unfortunately, it still looks like I'm getting errors when I try to add the following to my code.
Copy code
property name="logger     inject="logbox:logger"
.
.
.
logger.warn("I am a test message!")
p
What error are you receiving...stacktrace?
j
My error looks something like this:
Copy code
Expression:  Variable LOGGER is undefined.

[{"RAW_TRACE":"\tat cfrecordFormSubmission2ecfc699891102$funcRECORDFORMSUBMISSION.runFunction(C:\\Users\\jsteve\\OneDrive - Loeb Electric\\Documents\\GitHub\\custom-form-app\\includes\\ajaxColdfusion\\fillout\\recordFormSubmission.cfc:157)","LINE":157,"COLUMN":0,"TEMPLATE":"C:\\Users\\jsteve\\OneDrive - Loeb Electric\\Documents\\GitHub\\custom-form-app\\includes\\ajaxColdfusion\\fillout\\recordFormSubmission.cfc","ID":"??","TYPE":"CFML"}]
It looks like this in the file that triggers the error:
Copy code
component
{
     property name="logger"     inject="logbox:root";
     .
     .
     .
     logger.error("Test error message!");
}
So I'm thinking that the logger object isn't being injected.
b
Are you creating the instance of your CFC via wirebox?
That's the key here, un fact you didn't even need to map it
j
The CFC is not being created via wirebox. It is being directly hit by an ajax request.
b
Just running getInstance( "path.to.your.component" ) would create it
Yeah, that won't work
Wirebox must create the CFC or no autowiring happens!
How else would the injections get processee?
You can try extending ColdBox's remote proxy, it has logic in the puesdo constructor to try auto wiring itself.
j
I might just move the CFCs to live in the handlers folder. I think that might make things a lot easier.