>> GreenByte.info By Nick Tong (quiksilv) | Supported by: TalkWebSolutions.co.uk

Setting up Coldspring within fusebox via the CS lexicons

After a couple of hours chatting back and forth on the fusebox mailing list I've got the coldSpring lexicons working. The reason this took so long was because I had a concern that to use any of the lexicons you have to use the initialize lexicon to setup coldspring (CS). This meant that I had to change my code that I'd already setup, somehow that didn't feel right. That said it's just a 5 min change (once you know what you're doing).

Cutting to the chase:

To get CS setup you need to initilise the CS factory, you do this using the initialize verb mentioned above. The best place to do this is in the appinit section of fusebox.xml.cfm as this is called as you start your app (it's like the onApplicationStart function in application.cfm). Within this function I call a fuseaction in my model circuit:

<appinit>
   <fuseaction action="m.coldSpringSetup" />
</appinit>
NB: Make sure you use "fuseaction action="m.coldSpringSetup" and not "do action="m.coldSpringSetup" "

Then inside my model circuit i have this fuseaction

...
<circuit access="public" xmlns:cs="coldspring/">
<fuseaction name="coldSpringSetup">
   <cs:initialize    coldspringfactory="servicefactory" defaultproperties="#application.defaultProperties#">
      <cs:bean beanDefinitionFile="#expandPath('/config/coldspring.xml.cfm')#" />
   </cs:initialize>
</fuseaction>
...

So what is it that we're doing here.
<circuit access="public" xmlns:cs="coldspring/"> - we're declaring the namespace for the coldspring lexicons
cs:initialize - this calls the initialize verb from the coldspring lexicon folder.
coldspringfactory="servicefactory" - this is giving the coldspring factory it's name.
cs:bean - this calls the bean verb from the coldspring lexicon folder.
beanDefinitionFile="#expandPath('/config/coldspring.xml.cfm')#" - this passes my config file to coldspring

Once you've done this you'll all set up...wait, what! Yup, it's that easy.

Next you'll want to call some a method within CS, right?


<cs:get    bean="categoryService"
         returnvariable="variables.categoryService"
         coldspringfactory="servicefactory" />

So what's going on here:
cs:get - this invokes the get verb from the coldspring lexicon folder.
bean="categoryService" - this tells CS which bean (function or method) in needs to get from the CS factory
coldspringfactory="servicefactory" - this tells CS which coldspring factory to use.

And that all folks!

You can then call your objects as normal

<invoke object="variables.categoryService" methodcall="productCategorySelect(attributes.catalogueID)" returnVariable="qProductCategoryList" />
A big thanks goes out to nathan strutz and Qasim Rasheed for these lexicons.


 
Comments
nick tong's Gravatar Note: If you set up reactor via CS then you can add this to your "coldSpringSetup" fuseaction:

<cs:get bean="ReactorFactory"
            returnvariable="application.reactor"
            coldspringfactory="servicefactory" />
# Posted By nick tong | 16/03/07 23:10 | Report abusive comment
Dan Lancelot's Gravatar Thanks for that Nick - will definately make my life easier when i start to look at CS in (hopefully) a few weeks...

One question:
within the <cs:get .../> tag you set: coldspringfactory="servicefactory"

I presume this must tie up with the application.servicefactory object that was created within the <cs:initialise .../> tag

How come its referenced as servicefactory and not as application.servicefactory?
# Posted By Dan Lancelot | 16/03/07 23:23 | Report abusive comment
nick tong's Gravatar Hi Dan, glad to help.

The initlize verb prepends the coldspringfactory with: myFusebox.getApplication().getApplicationData().#fb_.coldspringfactory#

#fb_.coldspringfactory# being the name you give it.

The get verb also uses this to get the CS factory name:

#fb_.returnvariable#myFusebox.getApplication().getApplicationData().#fb_.coldspringfactory#.getBean
# Posted By nick tong | 16/03/07 23:26 | Report abusive comment
Dan Lancelot's Gravatar Ahh - thanks - that makes sense then.
# Posted By Dan Lancelot | 16/03/07 23:28 | Report abusive comment
Sean Corfield's Gravatar Note that "servicefactory" is the default so you can omit it from the cs:initialize and cs:get verbs.

You only need that attribute if you want to use a different variable name - or have multiple factories (so you'd have multiple cs:initialize tags with different coldspringfactory attributes).
# Posted By Sean Corfield | 20/03/07 03:08 | Report abusive comment
Howard Fore's Gravatar Nick, thanks for this, looks cool. What's the application.defaultProperties that's referred to in the cs:initialize tag?
# Posted By Howard Fore | 24/08/07 02:46 | Report abusive comment
Nick Tong's Gravatar @Howard - thanks. The applicationdefaultproperties argument is where I store my dynamic valubales that i was to pass into the ColdSpring's xml file i.e. my datasource name. Dan Vega has a good post on passing entries into CS here: http://www.danvega.org/blog/index.cfm/2006/11/25/P...
# Posted By Nick Tong | 24/08/07 07:47 | Report abusive comment
Toni's Gravatar bind p name or??
# Posted By Toni | 13/04/08 07:31 | Report abusive comment
BlogCFC was created by Raymond Camden. This blog is running version 5.5.1.