[wirebox] Standalone init issues

I’m new to using wirebox and we’re working on using it to do D.I. on a legacy application that we’re gradually improving as we go and hopefully will eventually go full-fledged with Coldbox on. For now though, we just wanted to use wirebox to set up a bean factory and handle D.I. but I’m concerned about how often we are getting errors on development and not sure what we’re doing wrong or if such problems are typical. In the past I’ve generally used Coldspring, but since that’s not being developed any more I thought I’d go with wirebox instead.

I have the init getting called at OnApplicationStart() as well as if the user tries to manually reinit it or is running local development. However, it frequently seems to time out (typically a loop timeout from util.cfc) when parsing the config file and loading the beans (all singletons). I have this:

application.wirebox = createObject(“component”,“wirebox.system.ioc.Injector”).init(binder = “config.wirebox_config”, singletonReload = true);

And the config is fairly straightforward with 3 directories that we load via mapDirectory() commands and then other CFCs with additional params that get loaded separately.

Even if we don’t get a timeout error we often get an error the first time the code tries to read one of the components in the wirebox, which appears to be a problem with none of the CFCs getting properly loaded. So we get an “instance not found” error. And have to manually reinit the wirebox a few times to get it working again.

Any ideas?? I’m very leery about moving this to production as often as it seems to fail in development right now.

Also, not sure what version we have as the standalone files don’t seem to include a text with version information but it would be a fairly recent release. If there have been any updates since the beginning of the year that might resolve this I can certainly look at updating our code base.

Mary Jo

Mary Jo, singletonreload is not an argument to the injector’s init() method.

http://apidocs.ortussolutions.com/WireBoxDocs-1.8.0/index.html?wirebox/system/ioc/Injector.html

I don’t think that’s related to your issues, but I thought i would mention it. In case you’re curious, singleReload is a ColdBox setting that tells ColdBox to call the injector.clearSingletons() method on every request.

So on to your issue; some questions:

  • How many CFCs are you mapping total with the mapDirectories?
  • Is your init code thread safe in case multiple requests all hit the server at once to load the application?
  • If you pull some stack traces from the server while it’s loading up, what kind of activity do you see? It’s possible code in some of the CFC’s init methods could be slowing it down.
  • What’s your request timeout? Sometimes, it just takes a while to load everything up so you may need to increase the timeout to allow the application to fully load.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Mary Jo, singletonreload is not an argument to the injector’s init() method.

Ah okay, thanks. Wasn’t sure about that, so many examples are based on wirebox running on Coldbox so easy to miss things like this!

  • How many CFCs are you mapping total with the mapDirectories?

Two directories with about 14-16 CFCs each. I wasn’t sure whether it was better to combine more of them together, to minimize the amount of DI going on. I did try dropping the mapDirectory() and doing them all separately but that didn’t seem to be the issue.

  • Is your init code thread safe in case multiple requests all hit the server at once to load the application?

Good point, I will look at doing that. But since we have this issue primarily locally I don’t think that’s the problem here. We do see it on dev too from time to time, we just aren’t working on that environment as frequently. Locally I’ve sometimes run into this so bad at times that I’ve had to restart CF to get the wirebox to init.

  • If you pull some stack traces from the server while it’s loading up, what kind of activity do you see? It’s possible code in some of the CFC’s init methods could be slowing it down.

Hhm, I’ll have to figure out how to do that. I run on Mac locally but am more familiar with using CF on Windows (fairly recent switch that I’m still getting used to!)

  • What’s your request timeout? Sometimes, it just takes a while to load everything up so you may need to increase the timeout to allow the application to fully load.

Okay, will look at doing that as well. Thanks.

I’m working on improvements to my wirebox init particularly working to make sure it’s thread safe (using the ThreadSafe annotation and checking for any circular dependencies, not sure I have any but will make sure those are thread safe as well). But was wondering how people typically put the factory into application scope for standalone. Is doing it the way I have in onApplicationStart like this the best way to do it? Do I need to lock this statement as well?

application.wirebox = createObject(“component”,“wirebox.system.ioc.Injector”).init(binder = “config.wirebox_config”,

Mary Jo