How to get the an init() method in a cfc to work with WireBox

72 views
Skip to first unread message

Ryan Hinton

unread,
Jul 14, 2015, 2:46:50 PM7/14/15
to col...@googlegroups.com
Hello All,

I am attempting to use coldfumonkeh's OAuth2 cfc which has an init() method with required params in the init() method.

I am attempting to instantiate the cfc in a view cfm file in the following manner.  Also the oauth2 is in the models folder.
getModel('oauth2').init(strParamsVariable);

I am receiving the following error:
Type: Builder.BuildCFCDependencyException
Messages: Error building: oauth2 -> The CLIENT_ID parameter to the init function is required but was not passed in.

I have attempted to hard code this parameter in the init such as the following with no luck either:
getModel('oauth2').init(client_id=1);

I'm sure I am not doing something correctly and I did read on the WireBox refcard about possibly using onDIComplete annotation, but i get a feeling I should not need to use it in this case.  This would require adding another param in the oauth2.cfc for the init? That doesn't feel right for some reason.

Any assistance would be greatly appreciated!

Thank You,
Ryan Hinton

Ryan Hinton

unread,
Jul 14, 2015, 3:08:40 PM7/14/15
to col...@googlegroups.com
A couple of things to add:

1) I meant to say "This would require adding another *method*..." not params.

2) I was able to get it working by removing the init method from the oauth2.cfc altogether.

I don't know how detrimental this is yet by doing so, but i was able to get the expected results with my initial test code:

oauth2 = getModel('oauth2');
oauth2.setClient_ID('ryan');
writeOutput(oauth2.getClient_ID());

I'm still curious about whether how to use init() methods with WireBox.

Thanks for any help!
Ryan Hinton

br...@bradwood.com

unread,
Jul 14, 2015, 10:37:26 PM7/14/15
to col...@googlegroups.com
getModel('oauth2').init(strParamsVariable);
 
getModel() automatically calls the init() for you, so even though you're trying to call it a second time it's too late since the init() has required params and has already errored.
 
Your first option is to pass in the init args ad-hoc like so:
 
getInstance( name="myCFC", initArguments={} )
 
I don't recommend this approach though because then you must supply those arguments EVERY time you request the CFC plus you're mixing initialization details into a file that has no business worrying about it.
 
The ideal approach when working with a 3rd party lib with required init args is to map it in your config/WireBox.cfc
 
map( "alias" )
  .to( "path.to.cfc" )
  .asSingleton()
  .initArg( name="argName", value="constant" )
  .initArg( name="argName2", ref="anotherMappingName" )
  .initArg( name="argName3", dsl="coldbox:setting:settingName" );
 
Now that you've told WireBox how to build this CFC, you can just request it with getInstance( "alias" )
 
Now, if you REALLY don't; want to do the mapping and you're ok fiddling around with the code in the 3rd CFC (not generally recommended) you can just add an "inject" annotation in the arguments for that CFC's init.  WireBox will see these when it builds the CFC and provide the init args automatically because it's just that awesome.
 
thirdParty.cfc
component {
  /**
  * @arg1.inject mappingName
  * @arg2.inject coldbox:setting:settingName
  */
  function init( required arg1, required arg2 ) {}
}

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/1bdf182a-4027-4ff3-a8ea-0f08029a1218%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ryan Hinton

unread,
Jul 15, 2015, 10:07:51 AM7/15/15
to col...@googlegroups.com
Hi Brad!

What a great response!  Thank you so much for the detailed explanation!

Since my last post, I realized that I need more than just what the oauth2.cfc offers, so I am spring boarding off of coldumonkeh's version and making a new one, so I will opt to actually use the 3rd option with the inject annotation in my version.

Thank you again, Brad! 
Ryan Hinton

On Tuesday, July 14, 2015 at 2:46:50 PM UTC-4, Ryan Hinton wrote:

br...@bradwood.com

unread,
Jul 15, 2015, 6:42:44 PM7/15/15
to col...@googlegroups.com
Cool, if you search Forgebox, you'll see that Jeremy DeYoung and William Eatman both have Oauth projects that might have some bits you can use.
 
If you do come up with a project of your own form your fork of Coldfumonkeh's, be sure to contribute it back on ForgeBox.  I'd wrap it up as a module so it can register its models with ForgeBox simply by being installed.  Plus, that can help standardize the config by reading it from the Coldbox config so it's more uniform to install.

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:24687] Re: How to get the an init() method in a cfc to work with WireBox
From: "Ryan Hinton" <ryanh...@gmail.com>
--
--
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.
Reply all
Reply to author
Forward
0 new messages