Hi Robert, you don’t need to worry about any of those online approaches.
You’re using ColdBox so we’ve already given you solutions for adding
mixins out-of-the-box
Your first option is the *applicationHelper *setting (Name changed from
UDFHelper in ColdBox 3.x).
http://coldbox.ortusbooks.com/content/configuration/configuration_directives/coldbox.html
applicationHelperA list or array of absolute or relative paths to a UDF
helper file. The framework will load all the methods found in this helper
file globally. Meaning it will be injected in ALL handlers, layouts and
views.
In /config/ColdBox.cfc
coldbox={
applicationHelper = “includes/helpers/ApplicationHelper.cfm”
}
You second option is a bit more laser and allows you to add mixins on an
individual CFC basis. You can give WireBox a list of files to include UDFs
from into your components.
If you like the WireBox DSL for mapping your components it would look like
this in your /config/WireBox.cfc:
map(“MyService”)
.to(“model.UserService”)
.mixins(“/helpers/base”);
My favorite WireBox approach though is to keep the config for a CFC right
there inside the component. That’s why we also have the annotation
approach for this feature:
component mixins=“/helpers/base”{
}
Thanks!
~BradOn Saturday, March 21, 2015 at 3:25:48 AM UTC-5, Robert Munn wrote:
I have a Coldbox app and I want to inject a common set of methods into my
handlers. I was thinking of using a mixin approach, and I was re-reading
Sean Corfield’s post about mixins:
http://corfield.org/blog/index.cfm/do/blog.entry/entry/Mixins
I was wondering what people thought of the idea of modifying the base
Component class to add the mixin function, and if this is a candidate for
the kind of functionality that might be standard in a new Lucee version.
Since I am only need the functionality for a subset of components, I don’t
necessarily want to add the method to every component I instantiate, but
the alternative is more or less to copy what Sean’s function does inline or
in a base class.
Here is Sean’s function:
function mixin(type) {
var target = createObject("component",arguments.type);
structAppend(this,target);
structAppend(variables,target);
}
I suppose I could extend coldbox.system.EventHandler to a base handler
class of my own so I can add the mixin method there. I’d rather not,
though. Other ideas?
Robert