RE: [coldbox:16874] [ColdBox 3.5.3] How to best make a helper component available?

My first suggestion is to use the SessionStorage plugin built into ColdBox. It is available in any framework object as getPlugin(“sessionStorage”) and can be wired into models with the WireBox DSL “coldbox:plugin:sessionStorage”.

If you must use your session broker, my next suggestion is to switch from ColdSpring to WireBox. WireBox is much cooler and integrated tighter into your application to allow you to access it anywhere. There’s also a feature of the ColdBox Platform Utilities which will automatically convert your cumbersome ColdSpring XML config into a slick WireBox programmatic config for you.

wirebox.cfc
map(“sb”).to(“com.whatever.sessionBroker”).asSingleton();

In views as getModel(“sb”)
or injected in models with the DSL “model:sb”, or simply:
property name=“sb” inject;

If you must use ColdSpring, I would recommend using the IOC Builder which would allow you to inject your session broker with the DSL “IOC:SessionBroker”.

If you wanted to get funky and cool with WireBox, you could register a custom builder in WireBox which would let you map your own DSL namespace. Then you could inject it with a DSL similar to “myCustomNameSpace:sb” which of course assumes you wrote a builder to handle that name space which knew what to do with a second stage DSL of “sb”. You could even create a WireBox mapping that pointed to that DSL
map(“sb”).toDSL(“myCustomNameSpace:sb”) and then use that ID for injection.

If you don’t want to use the IOC builder or create a custom builder, I would recommend wrapping your session broker in an intermediate service that WireBox created just because it’s so much easier to get your models in my opinion when WireBox is handling them.

If what you really want is for your session broker to be automatically available everywhere in your app without actually having to inject or retrieve it, you can put it in the private request collection at the beginning of every request with an onRequestStart handler or a preProcess interceptor. Alternatively, you could create a UDF in your UDF library (which still wouldn’t exist in your models) that created a ColdBoxProxy object that it used to get your ioc plugin. I wouldn’t recommend either of those last two ideas however, as they’re messy and break encapsulation.

Hopefully that gives you some starting points.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

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