IoC Plugin Returns Empty Struct

Hello! I have just started migrating some of my projects over to
ColdSpring after using my own IoC factory for several years now. I'm
almost there as far as the integration with ColdBox goes, but am
running up against a brick wall. A quick search of the group did not
supply any answers, so I figured I'd go ahead and post the question.

In my main.onAppInit() everything seems to be working fine. When I
call getPlugin('ioc') from there, I receive a properly instantiated
ColdSpring BeanFactory. At some point after this, it seems to fall
apart. I have a couple of custom plugins that are called later on in
the request life cycle. By the time the request gets to them, the
getPlugin('ioc') call within them returns an empty struct.

I have the following in my coldbox.xml:

  <Setting name="HandlersIndexAutoReload" value="false" />
  <Setting name="ConfigAutoReload" value="false" />
  <Setting name="HandlerCaching" value="true"/>
  <Setting name="IOCFramework" value="coldspring" />
  <Setting name="IOCDefinitionFile" value="config/coldspring.xml.cfm" /

  <Setting name="IOCObjectCaching" value="false" />

It's probably something really simple that I'm overlooking, or maybe
I'm just misunderstanding how the IoC plugin works. Either way, any
guidance in the correct direction would be most appreciated.




You don’t need to set anything onAppInit(). ColdBox does all the work for you :slight_smile:

Just set IOCFramework,IOCDefinitionFile and IOCObjectCaching in ColdBox.xml.cfm
and call getPlugin(‘ioc’).getBean(’‘myMisterBean’)

That’s it!


Did you check the ColdBox TransferSample?

BTW Don’t forget to use fwreinit=1 in your url when adjusting your config file.



Thanks for the reply. The stuff I’m doing in onAppInit() has nothing to do with attempting to configure the IoC plugin. It is stuff to init the application itself, which happens to use the IoC plugin. I mentioned the onAppInit() in my post only to make the point that the plugin does return ColdSpring at that point in the request life cycle. That indicates to me that ColdSpring is being loaded just fine, but since getPlugin(‘ioc’) later returns an empty struct, it seems that it is not being cached.

So something is missing in the middle.

What about a cfdump in your handler action function before your other plugin calls?

Please show me your handler code.

<cfdump var="#getPlugin('ioc')#" /> inside onAppInit() shows the
fully-instantiated ColdSpring BeanFactory.

I should clarify my last post.

^That shows me a fully instantiated ColdSpring BeanFactory. If I run getBeanDefinitionList() on it, I also see all of my defined beans. Again, I know that everything is behaving as expected up until that point, but somehow it is being “lost” after processing leaves onAppInit().



Okay, I figured out what the problem was. I’m not really understanding why it behaves this way, but I’m pacified for now because I found a “fix” for my issue.

The Problem

In the init() method of my custom plugins, I was calling for the IoC plugin so that I could wire up the custom plugin. For some reason, these calls resulted in an empty struct being returned.

The Fix

I removed the getPlugin(‘IoC’) calls from the custom plugins, and added autowire=“true” to the tag, and also added get/set methods for the dependencies.

The Result

I now have my custom plugins all wired up, and the IoC plugin works as expected.

Anyways, hopefully one day I’ll understand how calling the IoC plugin from the init() of a custom plugin can somehow magically wipe out the IoCFactory, but at least I’m back in business now.

Thanks for your input and responses, Ernst. :slight_smile:


That is good news for sure Matt. I would recommend that you use cfproperty to describe your dependencies. This way its more descriptive than setter injection.

I will investigate on your other issue