Inject Setting into a service

Hi guys,

I’m having an issue injecting a setting into a service.

I’m trying to inject like so:

And have defined the setting in ColdBoxConfig like so:

// Google
google = {
mapsAPIKey = “myAPIKey”
},

I’ve defined it as a structure because i’m going to be adding additional settings in the future.

I’m then referring to the setting inside the service like so:

…and receive an error saying that variable mapsAPIKey is undefined.

This is probably a simple one but can’t figure out what i’m doing wrong.

Thanks much!

Nolan

Can you retrieve “Google”?

Hi,

Yes I was to retrieve the structure when I change the cfproperty to: inject=“coldbox:setting:google”

Makes sense. Out of curiosity though, is there a way to inject a setting that exists in a structure or is it best practice to inject the full structure/setting and then reference the key that is needed?

Thanks.

Nolan

No, I don’t believe you can parse the structure on injection without implementing some custom behavior via WireBox–which, I still have not played with… But, from what I read, it seems like you could solve your issue with WireBox–I just don’t know how yet.

Hi Nolan,

It seems like a bug in autowire. Its treating as string “google.mapsAPIKey”
though it should be treated as nested structure

Will be fixed in coming release.

Thanks
Sana

Sana,

I believe all failed injections are treated as a empty string. If ColdBox can parse the stuct and insert just the value of a nested key, that would be fantastic; however, I don’t believe this is really a bug.

Thanks,

Aaron

Plus you have to use evaluations for this and not find that good usage. I suggest wiring the parent setting and then grabbing what you need or get funky and build your own setting custom dsl that can do this for you in wirebox

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