[ColdBox-BE 4.0] Best practice for utility components

On a previous project I had worked on where the client was using an earlier version of CB 3, their implementation of utility components was the use of /plugins and getting their utilities in the manner of (for example):

Since that is deprecated in 4, and I am not sure if it was the proper way to use utilities before, what is the recommended approach for creating a set of utilities? There’s certainly helpers which can be used throughout the framework. Is this the best implementation? For handlers/models, I feel some utilities would be best used as injected properties rather than includes. Also, what about directory naming convention?

Generally speaking, just dump your utility CFC directory in the models folder (or models/util) if you wish and replace your getPlugin() call with getInstance() and Wirebox will give it to you.

You’ll want to remove any extends=“coldbox.system.Plugin” bit you might have and make sure you weren’t using anything from the Plugin super class (if you were, that’s fine, just inject what you need).

getMyPlugin( “foobar” )
just becomes
getInstance( “foobar” )

Or, if it just want to inject it since it’s probably a singleton, inject it just like any other model:
property name=“foobar” inject=“coldbox:myplugin:foobar”;
just becomes
property name=“foobar” inject=“foobar”;

what about directory naming convention?

There are none. Just put them in a place that makes sense to you and use WireBox as normal to map them.

Perfect, thanks as always!