[Coldbox-3.6.0] Using standalone wirebox with custom tags

I have a custom tag that has dependencies that I’d like to inject via Wirebox. Our code base is currently very large and we’re migrating pieces of it to coldbox a bit at a time from model-glue.

While we do this migration we are using standalone Wirebox with our model-glue code. In one of the controllers there we have access to wirebox and we make use of this custom tag. I know that the custom tag has a CALLER scope, but I’ve tried putting a reference to our wirebox instance in the controller’s variables scope, in the function’s local scope, and when I debug and inspect caller when execution gets inside the custom tag I don’t see wirebox there.

This isn’t strictly a coldbox-y question, or maybe not even a wirebox question per se, but I’m wondering if anyone has been able to use wirebox in a custom tag.

Additional details:

  • we make use of this custom tag in views also and putting wirebox there does let it show up in the caller scope ok - it’s just when we use the tag in a cfc function that I run into the issue
  • since we use it tons of places it would be desirable to not have to go update every place the tag is used and pass wirebox in manually via an attribute on the custom tag

Has anyone tried anything like this? I’d prefer to avoid doing CreateObject() calls in our custom tags if it’s possible.

The easiest method might be to enable scope registration in WireBox and simply access it as application.wirebox.getInstance(“blah”) if you need objects from within your custom tags.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

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

Have you thought about using the HTML Helper, but a custom one to do this instead of tags?

Thanks for the suggestions guys. The HTML helper would be useful, I think, for some of what we do, but our custom tags often do a lot of non-HTML-ish stuff as well. The scope registration sounds intriguing. I hadn’t seen it in the docs yet and will look into it. We’re trying to move to using a facade for external scopes in our code to make it easier to test our code in isolation I’m ok referencing the application scope directly since this is a custom tag situation (does one unit test custom tags? hmm). However, the issue I have there is that our custom tags are referenced in both coldbox code and legacy model-glue code that will take a while to move to coldbox. Until we get everything moved into CB we have 2 wirebox instances running, each with it’s own appropriate binder. They’re both registered in the application scope, but the tag will have no idea whether it’s being called from CB or MG. Any ideas on how to ensure it picks the right injector?

thanks again, btw

I just realized that I forgot to put a period after ‘isolation’ and before ‘I’m’. Sorry about any ensuing confusion :slight_smile: Or maybe it was a ‘, but’. I’m not sure.