I have some common UDFs and CFCs that I'd like to make available to all my controllers. I'm using Model-Glue 3. I've thought of several ways of doing so:
<cfinclude>
's to the UDFs and instantiates the CFCs. All other controller inherit from this controller.ColdSpring.xml
to make the CFCs into beans. Then make it available to the controller using the beans
attribute in ModelGlue.xml
.onRequestStart
which will instantiate the CFCs and store them in the event
object. Then the controllers will access the CFCs by grabbing them directly out of the event
object.My question is, what is the method used by most people to make a common set of UDFs and CFCs available to all controllers?
I would use option 2 above.
For those objects that need the helper methods I would use DI to inject a helper object into them. This will be more flexible going forward.
I do not like the idea of a base object with all of the helpers. Here is why:
What if later you want to break up the helpers in multiple CFCs? You can't. Depending on how many help functions you have and how many it could grow into, this could make your objects ugly. What if you someday have 50 helper functions. Do you really want your controllers having 50 extra methods that really have nothing to do with their primary concern.
Separations of concerns. Controllers should worry about being controllers. They should nto be loaded down with additional functions so that they know how to format strings. That should be handled by a StringHelper or something.
The other two options just don't sound great. What is the Helpers scope?