Mixins in cfcs

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

You might want to take a look at “Virtual Inheritance” in Wirebox:

I had missed this before when searching for “mixins”.

HTHOn 21 March 2015 at 08:25, Robert Munn <@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


You received this message because you are subscribed to the Google Groups
“Lucee” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to lucee+unsubscribe@googlegroups.com.
To post to this group, send email to lucee@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/lucee/9B44D0F3-060E-4384-9D1C-A0D10AEBA640%40gmail.com
https://groups.google.com/d/msgid/lucee/9B44D0F3-060E-4384-9D1C-A0D10AEBA640%40gmail.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.


Pixl8 Interactive, 3 Tun Yard, Peardon Street, London
SW8 3HT, United Kingdom

T: +44 [0] 845 260 0726• W: www.pixl8.co.uk• E: info@pixl8.co.uk
Follow us on: Facebook http://www.facebook.com/pixl8 Twitter
http://www.twitter.com/pixl8 LinkedIn
http://www.linkedin.com/pixl8CONFIDENTIAL
AND PRIVILEGED - This e-mail and any attachment is intended solely for the
addressee, is strictly confidential and may also be subject to legal,
professional or other privilege or may be protected by work product
immunity or other legal rules. If you are not the addressee please do not
read, print, re-transmit, store or act in reliance on it or any
attachments. Instead, please email it back to the sender and then
immediately permanently delete it. Pixl8 Interactive Ltd Registered in
England. Registered number: 04336501. Registered office: 8 Spur Road,
Cosham, Portsmouth, Hampshire, PO6 3EB

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 :slight_smile:

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

Interesting, but I don’t think that approach will work in this case
because I am adding functionality to handlers, which are not listed in
Wirebox.

Handlers are managed through WireBox. Did you try any of those approaches?On 22 March 2015 at 07:22, Robert Munn <@Robert_Munn> wrote:

Interesting, but I don’t think that approach will work in this case
because I am adding functionality to handlers, which are not listed in
Wirebox.

On Mar 21, 2015, at 5:43 AM, Dominic Watson <@Dominic_Watson> wrote:

You might want to take a look at “Virtual Inheritance” in Wirebox:
Introduction - ColdBox HMVC Documentation

I had missed this before when searching for “mixins”.

HTH

On 21 March 2015 at 08:25, Robert Munn <@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


You received this message because you are subscribed to the Google Groups
“Lucee” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to lucee+unsubscribe@googlegroups.com.
To post to this group, send email to lucee@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/lucee/9B44D0F3-060E-4384-9D1C-A0D10AEBA640%40gmail.com
https://groups.google.com/d/msgid/lucee/9B44D0F3-060E-4384-9D1C-A0D10AEBA640%40gmail.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.


Pixl8 Interactive, 3 Tun Yard, Peardon Street, London
SW8 3HT, United Kingdom
T: +44 [0] 845 260 0726• W: www.pixl8.co.uk• E: info@pixl8.co.uk
Follow us on: Facebook http://www.facebook.com/pixl8 Twitter
http://www.twitter.com/pixl8 LinkedIn http://www.linkedin.com/pixl8CONFIDENTIAL
AND PRIVILEGED - This e-mail and any attachment is intended solely for the
addressee, is strictly confidential and may also be subject to legal,
professional or other privilege or may be protected by work product
immunity or other legal rules. If you are not the addressee please do not
read, print, re-transmit, store or act in reliance on it or any
attachments. Instead, please email it back to the sender and then
immediately permanently delete it. Pixl8 Interactive Ltd Registered in
England. Registered number: 04336501. Registered office: 8 Spur Road,
Cosham, Portsmouth, Hampshire, PO6 3EB


You received this message because you are subscribed to the Google Groups
“Lucee” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to lucee+unsubscribe@googlegroups.com.
To post to this group, send email to lucee@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/lucee/CAEYvUx%3D91a9-A%2BTPV1BerDCsy%2B_USQ0hiy_03GxMtFQ97WmSVw%40mail.gmail.com
https://groups.google.com/d/msgid/lucee/CAEYvUx%3D91a9-A%2BTPV1BerDCsy%2B_USQ0hiy_03GxMtFQ97WmSVw%40mail.gmail.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.


You received this message because you are subscribed to the Google Groups
“Lucee” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to lucee+unsubscribe@googlegroups.com.
To post to this group, send email to lucee@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/lucee/DD3703C9-4ADE-4360-9E0A-6F37E18D2FF2%40gmail.com
https://groups.google.com/d/msgid/lucee/DD3703C9-4ADE-4360-9E0A-6F37E18D2FF2%40gmail.com?utm_medium=email&utm_source=footer
.

For more options, visit https://groups.google.com/d/optout.


Pixl8 Interactive, 3 Tun Yard, Peardon Street, London
SW8 3HT, United Kingdom

T: +44 [0] 845 260 0726• W: www.pixl8.co.uk• E: info@pixl8.co.uk
Follow us on: Facebook http://www.facebook.com/pixl8 Twitter
http://www.twitter.com/pixl8 LinkedIn
http://www.linkedin.com/pixl8CONFIDENTIAL
AND PRIVILEGED - This e-mail and any attachment is intended solely for the
addressee, is strictly confidential and may also be subject to legal,
professional or other privilege or may be protected by work product
immunity or other legal rules. If you are not the addressee please do not
read, print, re-transmit, store or act in reliance on it or any
attachments. Instead, please email it back to the sender and then
immediately permanently delete it. Pixl8 Interactive Ltd Registered in
England. Registered number: 04336501. Registered office: 8 Spur Road,
Cosham, Portsmouth, Hampshire, PO6 3EB

Interesting, but I don’t think that approach will work in this case because I am adding functionality to handlers, which are not listed in Wirebox.On Mar 21, 2015, at 5:43 AM, Dominic Watson <@Dominic_Watson> wrote:

You might want to take a look at “Virtual Inheritance” in Wirebox: Introduction - ColdBox HMVC Documentation

I had missed this before when searching for “mixins”.

HTH

On 21 March 2015 at 08:25, Robert Munn <@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


You received this message because you are subscribed to the Google Groups “Lucee” group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+unsubscribe@googlegroups.com.
To post to this group, send email to lucee@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/9B44D0F3-060E-4384-9D1C-A0D10AEBA640%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Pixl8 Interactive, 3 Tun Yard, Peardon Street, London
SW8 3HT, United Kingdom
T: +44 [0] 845 260 0726• W: www.pixl8.co.uk• E: info@pixl8.co.uk
Follow us on: Facebook Twitter LinkedIn
CONFIDENTIAL AND PRIVILEGED - This e-mail and any attachment is intended solely for the addressee, is strictly confidential and may also be subject to legal, professional or other privilege or may be protected by work product immunity or other legal rules. If you are not the addressee please do not read, print, re-transmit, store or act in reliance on it or any attachments. Instead, please email it back to the sender and then immediately permanently delete it. Pixl8 Interactive Ltd Registered in England. Registered number: 04336501. Registered office: 8 Spur Road, Cosham, Portsmouth, Hampshire, PO6 3EB


You received this message because you are subscribed to the Google Groups “Lucee” group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+unsubscribe@googlegroups.com.
To post to this group, send email to lucee@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/CAEYvUx%3D91a9-A%2BTPV1BerDCsy%2B_USQ0hiy_03GxMtFQ97WmSVw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Handlers are still created by WireBox. You should be able to just add the
“mixins” annotation to the CFC and it will pick it up. I think you can
also create an explicit mapping named after the handlers full path
(handlers.myHandler) but I’d need to test that real quick to confirm.

Thanks!

~Brad

ColdBox Platform Evangelist
*Ortus Solutions, Corp *

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.comOn Sun, Mar 22, 2015 at 2:22 AM, Robert Munn <@Robert_Munn> wrote:

Interesting, but I don’t think that approach will work in this case
because I am adding functionality to handlers, which are not listed in
Wirebox.

On Mar 21, 2015, at 5:43 AM, Dominic Watson <@Dominic_Watson> wrote:

You might want to take a look at “Virtual Inheritance” in Wirebox:
Introduction - ColdBox HMVC Documentation

I had missed this before when searching for “mixins”.

HTH

On 21 March 2015 at 08:25, Robert Munn <@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


You received this message because you are subscribed to the Google Groups
“Lucee” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to lucee+unsubscribe@googlegroups.com.
To post to this group, send email to lucee@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/lucee/9B44D0F3-060E-4384-9D1C-A0D10AEBA640%40gmail.com
https://groups.google.com/d/msgid/lucee/9B44D0F3-060E-4384-9D1C-A0D10AEBA640%40gmail.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.


Pixl8 Interactive, 3 Tun Yard, Peardon Street, London
SW8 3HT, United Kingdom
T: +44 [0] 845 260 0726• W: www.pixl8.co.uk• E: info@pixl8.co.uk
Follow us on: Facebook http://www.facebook.com/pixl8 Twitter
http://www.twitter.com/pixl8 LinkedIn http://www.linkedin.com/pixl8CONFIDENTIAL
AND PRIVILEGED - This e-mail and any attachment is intended solely for the
addressee, is strictly confidential and may also be subject to legal,
professional or other privilege or may be protected by work product
immunity or other legal rules. If you are not the addressee please do not
read, print, re-transmit, store or act in reliance on it or any
attachments. Instead, please email it back to the sender and then
immediately permanently delete it. Pixl8 Interactive Ltd Registered in
England. Registered number: 04336501. Registered office: 8 Spur Road,
Cosham, Portsmouth, Hampshire, PO6 3EB


You received this message because you are subscribed to the Google Groups
“Lucee” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to lucee+unsubscribe@googlegroups.com.
To post to this group, send email to lucee@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/lucee/CAEYvUx%3D91a9-A%2BTPV1BerDCsy%2B_USQ0hiy_03GxMtFQ97WmSVw%40mail.gmail.com
https://groups.google.com/d/msgid/lucee/CAEYvUx%3D91a9-A%2BTPV1BerDCsy%2B_USQ0hiy_03GxMtFQ97WmSVw%40mail.gmail.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.


You received this message because you are subscribed to a topic in the
Google Groups “Lucee” group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/lucee/m5Goy9azOe0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
lucee+unsubscribe@googlegroups.com.
To post to this group, send email to lucee@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/lucee/DD3703C9-4ADE-4360-9E0A-6F37E18D2FF2%40gmail.com
https://groups.google.com/d/msgid/lucee/DD3703C9-4ADE-4360-9E0A-6F37E18D2FF2%40gmail.com?utm_medium=email&utm_source=footer
.

For more options, visit https://groups.google.com/d/optout.