Injecting Coldbox into service layer

My ultimate goal is to be able to access coldbox plugins inside my
service layer. I see this being accomplished in the new CCTApp sample
app via Coldspring. I haven't got that app running, but I assume that
it works.

So how can I inject coldbox into my service objects? I'm using
lightwire for my IOC, but I'll be darned if I can get it working. I'm
essentially mimicking the CCTApp coldspring config in my lightwire
config. Eventually I would wire the service objects in lightwire as
well, but here is my test code.

My light wire config:
        //Coldbox Factory


Inside the event handler:
       <cfset testColdbox = getPlugin("ioc").getBean("coldbox")>

The error is :

Element CONSTRUCTORDEPENDENCYSTRUCT is undefined in a CFML structure
referenced as part of an expression.

Any thoughts? Or am I barking up the wrong tree?


First of all Terry, be very careful to couple service objects with the ColdBox controller. Second, this might be lightwire related. However, try the following approach:

If you are using a programmatic config via lightwire then you have it really easy. The lightwire baseConfigObject, which should be extended ( coldbox.system.extras.lightwire.BaseConfigObject) already has the ColdBox controller available to you for usage in your configuration file. A good example is to set a dependency on an object:

addSetterProperty(“CategoryService”, “loggerPlugin”, getController().getPlugin(“logger”) );

From this example, I set a setter dependency on the CategoryService of a coldBox logger plugin. So there is no need to use the ColdboxFactory. The coldboxFactory is for coldspring, but in lightwire you have a programmatic approach, so its easier.

Another example is to inject as a constructor dependency, the ColdBox cache manager:

addConstructorProperty(“CategoryService”, “cacheManager”, getController().getColdboxOCM() );

Try this approach and let me know Terry. However, the factory approach should work, so maybe there is something weird going on. DO you mind posting your config here and I can let other people check it out.


Hi Luis,

I do agree with your first statement. I'm in the midst of setting up a
new app skeleton and was toying with various ideas for implementing my
security and getting a security plugin to work with a security

I am using a programmatic lightwire config and this proves that I
really need to study up more on using lightwire... Unfortunately there
isn't very much documentation on it. It is a powerful little component

I did use your addConstructorProperty() idea and the plugin is now
available in the Service object. That is exactly what I had in mind
last night.

Thanks much for the ideas.