wirebox/binder access from Colbox.cfc and afterConfigurationLoad

20 views
Skip to first unread message

Tom Miller

unread,
Jul 26, 2015, 9:10:13 PM7/26/15
to ColdBox Platform
I need to "override" an existing Wirebox mapping (currently in Wirebox.cfc) in a coldbox app from Colbox.cfc

I have a client who needs a different Service mapped for their application

i.e in Wirebox.cfc I have:

map("thisService").to("models.thisService");

and I want to add in Coldbox.cfc

function afterConfigurationLoad() {
  wirebox.getBinder().map("thisService").to("customerA.models.thisService");
}

However, wirebox and coldbox are at this point just Structs as they're "in" Coldbox.cfc.

How can I "get" access to the wirebox binder?

Thanks,


Tom.


br...@bradwood.com

unread,
Jul 26, 2015, 9:21:03 PM7/26/15
to col...@googlegroups.com
The code snippet you had in there doesn't work?  I would expect WireBox to be fully loaded up and operational in the "afterConfigurationLoad" interceptor point.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: br...@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com 
 
 
--------- Original Message ---------
--
--
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
For News, visit http://blog.coldbox.org
For Documentation, visit http://wiki.coldbox.org
For Bug Reports, visit https://ortussolutions.atlassian.net/browse/COLDBOX
---
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coldbox+u...@googlegroups.com.
To post to this group, send email to col...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/coldbox/659c7942-7eba-4395-822d-a7fbe4d5c9cd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

br...@bradwood.com

unread,
Jul 26, 2015, 9:23:43 PM7/26/15
to col...@googlegroups.com
Oh wait, I just saw that you're adding your interception point directly in the ColdBox config file.  There is a draw back to doing this, I don't think Coldbox.cfc behaves exactly like regular interceptors do that are declared in their file.  You're accessing the configuration structs in the variables scope instead of the injected objects that regular interceptors get access to. 
 
I would put that interceptor in its own CFC and register it as an interceptor in the config.  Then it should behave like you expect.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: br...@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com 
 
 
--------- Original Message ---------
Subject: [coldbox:24724] wirebox/binder access from Colbox.cfc and afterConfigurationLoad
From: "Tom Miller" <tom.m...@ebiz.co.uk>
Date: 7/26/15 8:10 pm
To: "ColdBox Platform" <col...@googlegroups.com>

--

Tom Miller

unread,
Jul 27, 2015, 9:45:33 AM7/27/15
to col...@googlegroups.com
Yes that's exactly the issue. Ok  - I was hoping there was "another" way to get to coldbox/wirebox, maybe application.wirebox.getBinder() or something like that as I'd have preferred to have kept it in one place.

If I have to separate it into an interceptor it's not the end of the world.

Thanks Brad.


Tom.



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



--

Tom Miller

Managing Director

DDI: 020 719 33777

email: tom.m...@ebiz.uk

=======================================================

 

eBiz

Centurion House, London Road, Staines, TW18 4AX

Tel: 08448 045046

web: ebiz.uk | www.facebook.com/eBizUK | www.twitter.com/eBizUK

 

 

Information contained in this communication may be confidential and/or legally privileged. It is intended solely for the use of the addressee and others authorized to receive it. If you are not the intended recipient any disclosure, copying, distribution or action taken in reliance on its contents is prohibited and may be unlawful. Neither eBiz | interactive business solutions nor the author accepts legal liability for the contents of this message. If you receive this communication in error please advise us at pri...@ebiz.co.uk

 

Whilst we run anti-virus software we are not liable for any loss/damage sustained as a result of software viruses. The recipients are advised to run their own anti-virus software

Andrew Scott

unread,
Jul 27, 2015, 10:14:12 AM7/27/15
to col...@googlegroups.com
Tom, there is a trick you can do which worked for me for something else.

What I worked on was using the afterInstanceCreation() in an interceptor.

Basically I used this to check the type of request and replace it with the object I wanted, I probably should be using the before creation (if there is one), but this was a quick and dirty solution for the time.

Now, I think having to change the mapping in your case raises a lot more issues as this could affect the other client/customer as well. Using this method is essential a factory pattern, as it checks the conditions and anything else and then loads the required object. Being transient would make this work well, I could see some potential issues with Singletons with this method, in the same way scope widening is an issue.

Now, and of course if the URL (Event) had what identifies the client/customer, this could then be included inside a module that could be excluded to your other customers/clients by using the eventpattern.

I am not sure that fixes your needs, but it may help in looking at it from another angle.



Regards,
Andrew Scott
WebSite: http://www.andyscott.id.au/


br...@bradwood.com

unread,
Jul 27, 2015, 11:45:36 AM7/27/15
to col...@googlegroups.com
I believe the controller is injected into instance.controller.  From there, you should be able to get anything you need.
 
instance.controller.getWireBox().getBinder().etc()
--------- Original Message ---------

Tom Miller

unread,
Jul 27, 2015, 12:36:10 PM7/27/15
to col...@googlegroups.com
Hmm - ok, I've gone the interceptor route, but my service isn't being autowired property.

When I go to use my service, I get variable "xxx" is not defined, even though it is:

i.e - in thisService.cfc I have

property name="searchService" inject="id:searchService";

function test() {
  return searchService.get("user=1");
}

When I do thisService.test(); I get: Error: variable [SEARCHSERVICE] doesn't exist

I'm guessing maybe it's just wiring the new service, but not autowiring the other dependencies within it?




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

Tom Miller

unread,
Jul 27, 2015, 12:45:16 PM7/27/15
to ColdBox Platform, tom.m...@ebiz.co.uk
Ok - If I add the mapping into Wirebox, it works. When I try to overwrite the mapping from 
within my interceptor, it doesn't.

Could it be that because the mapping already "exists" and I'm overwriting it, Wirebox already thinks it's done the dependency injection for that mapping already?

br...@bradwood.com

unread,
Jul 27, 2015, 2:20:13 PM7/27/15
to col...@googlegroups.com
Without seeing your code, I'm having a little troubles following you.  If the "old" mapping has already been injected somewhere, updating WireBox don't affect that-- only new injections going forward.  
 
The error that the variable doesn't exist though is interesting because typically that means autowiring didn't run at all.  Otherwise, WireBox would have errored since it couldn't resolve your dependency.
 
Where are you trying to inject the searchService?
 
Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: br...@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com 
 
 
--------- Original Message ---------
Subject: [coldbox:24731] Re: wirebox/binder access from Colbox.cfc and afterConfigurationLoad
From: "Tom Miller" <tom.m...@ebiz.co.uk>
--
--
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
For News, visit http://blog.coldbox.org
For Documentation, visit http://wiki.coldbox.org
For Bug Reports, visit https://ortussolutions.atlassian.net/browse/COLDBOX
---
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coldbox+u...@googlegroups.com.
To post to this group, send email to col...@googlegroups.com.

Tom Miller

unread,
Jul 27, 2015, 2:34:49 PM7/27/15
to col...@googlegroups.com
Perhaps this gist will explain better.

Essentially, I want to "update" an existing wirebox mapping so it uses a different model.


Thanks,


Tom.



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

br...@bradwood.com

unread,
Jul 27, 2015, 2:39:21 PM7/27/15
to col...@googlegroups.com
Ahh, so it's not the custom search service that's not being found-- it's the java search service that injected INTO the custom search service that's not being found!
 
What version of ColdBox are you using?  Is this CB 3.x or CB 4.x with the "java:" namespace registered via the cbjavaloader module?
--------- Original Message ---------

Tom Miller

unread,
Jul 27, 2015, 2:48:33 PM7/27/15
to col...@googlegroups.com
Yes exactly!

I just used the java dependency as an example so it was easy to see what was happening / how one service was different to the other.

It doesn't look like it's being autowired at all.

The funny thing is, both services actually DO have the same dependency.

If I update the wirebox.cfc config to use the mapping thats in the interceptor, everything works.

So there's definately something not happening, either because a.) afterConfigurationLoad is the issue, b.) the mapping names being the same has some affect, or c.) the dependency inside the new service has the same name as the old one and it's not rewiring that one...





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

Tom Miller

unread,
Jul 27, 2015, 3:02:47 PM7/27/15
to ColdBox Platform, tom.m...@ebiz.co.uk
Ok - taking a different approach, and using a custom binder and extending the default seems to work, i,e


Basically the same technique I'm using for Coldbox.cfc

Thanks for you help anyway Brad

Tom.


On Monday, July 27, 2015 at 2:10:13 AM UTC+1, Tom Miller wrote:
Reply all
Reply to author
Forward
0 new messages