In a ColdBox app how would I inject a component li...
# box-products
r
In a ColdBox app how would I inject a component like moment, which isn't a module, into an entity? I've put the
moment.cfc
in my
models/services
folder and have
property _name_='moment' _inject_='moment';
in my entity but I get back...
Copy code
Component [models.services.moment] has no accessible Member with name [VALUE]
What have I missed?
b
Stack trace?
Have you dumped out the injection to see what it is
r
Humm, that's gets a bit difficult for me. So this is a REST API I'm writing so it's in test case so I might have to peal some elements apart to get to that.
I can put my
property _name_='moment' _inject_='moment';
in my handler and that doesn't complain. I have've done any ColdBox work for some while but I'm remembering the last time I had an issue like this, injecting stuff into an entity, having to wrap it in a
onDIComplete()
method. I'll try that. Or do I have that wrong?
Nope -
General application error: key [FUNCTIONNAMES] doesn't exist
- what rabbit hole have I gone down now!
b
I'd need to see the stack trace
Sounds like you installed a module manually without its dependencies
Sentry, perhaps
r
This is not a module. It's a standalone component - https://github.com/AlumnIQ/momentcfc
c
Does that CFC have an init method that has any dependencies or values being set?
r
I guess I can just do
new models.services.moment()
Copy code
Init
The constructor takes 0, 1, or 2 arguments.

new moment() Use the current system time and the current system time zone
new moment( now() ) Use the specified time and the current system time zone
new moment( now(), 'America/Pacific' ) Use the specified time and the specified time zone
b
I understand the specific code you're trying to test is moment, but that doesn't mean the error you're seeing is necessarily related to it
LIke I said, you need to see the full stack trace. you're just guessing otherwise
Also note-- unless the moment CFC can be used as a singleton, injecting an instance of it likely won't work. It looks to be a transient
r
Sure, I understand, but the way I have things setup I'm not seeing the stack trace. Leave it with me and I'll come back to you want I can get the info you need to be able to help me.