ColdSpring - Locating CFC's outside Web Root???

I am in the process of creating a template application, using the following frameworks:

  • Fusebox 5.1
  • ColdSping
  • Transfer
I have run into the following issue.

We have tried to only have files within the web root, which should be accessible directly within the browser.

To do this, we have a web folder within the application folder - which is the root of the website. Within the application folder we have other folders, e.g.

  • cfc
  • circuits
  • config

All the cfcs go within the cfc folder (or subfolders).

Prior to implementing ColdSpring, we had an application variable which contained the location of the cfc folder, in dot notation:

<cfset application.config.dotroot = "appgroup.appname">
<cfset application.config.CFC_dotRoot = application.config.dotroot & ".cfc">
application.config.dotroot would be set dynamically dependant on the hostname of the application (development / staging / live etc.)

And then to initialise the object:

<cfset application.objManager['SecurityUtils']      = createObject( 'component', '#application.config.CFC_dotRoot#.security.SecurityUtils' )>

When implementing ColdSpring, there doesn't seem to be an easy way I can replicate this logic - ColdSpring wants a valid path in dot notation to the cfc within the class field of the bean tag.

I did try the following to see if it was possible to dynamically set the class attribute using the defaultProperties supplied to the Bean tag:

<bean id="SecurityUtils" class="${CFC_dotRoot}.security.SecurityUtils" />

But (as the name probably suggests), default properties only appear to be able to be used within properties, and not for setting attributes.

So my next plan of attack was to create a very basic factory CFC, which takes a couple of parameters, and returns the requested CFC.

This could then be instantiated by ColdSpring using the factory-bean and factory-method attributes of the bean tag:

Factory CFC

<cfcomponent hint="I am responsible for loading a CFC from a dynamic path" output="false">
   <cffunction name="GetCFC" hint="I return a CFC as requested" access="public" output="false" returntype="Any">
      <cfargument name="CFC_DotRoot" type="String" hint="The path to the root of the cfc folder, in dot notation" required="true" />
      <cfargument name="CFC_Path" type="String" hint="The path of the cfc in dot notation, relative to the root cfc folder" required="true" />
      <cfreturn createobject("component","#arguments.CFC_DotRoot#.#arguments.CFC_Path#").init() />
   </cffunction>
</cfcomponent>

ColdSpring:

<bean id="SecurityUtils" factory-bean="cfc.GenericFactory" factory-method="GetCFC">
   <constructor-arg name="CFC_DotRoot">
      <value>${CFC_dotRoot}</value>
   </constructor-arg>
   <constructor-arg name="CFC_Path">
      <value>security.SecurityUtils</value>
   </constructor-arg>
</bean>

This works fine - and loads the CFC from the dynamically specifed path.

I have the following reservations about this method:

  • It depends on init method being present
  • It depends on the init method taking no arguments
  • It would be possible to modify the factory to loop through the arguments array from 3 to length of array, and pass any arguments in to the init method of the created CFC
  • It doesn't feel right! - It seems like its working round ColdSpring -rather than with it...

That leaves me with a couple of options

  • Modify this method until it is sufficient for our requirements
  • Put my cfc folder within the web root
  • Specify full server paths in dot notation (or set up mappings) - and use ANT to modify if required for deployment

Am I barking up the wrong tree here? Is there something obvious I've missed? What does everyone else do?

Thoughts and comments most appreciated :)

Comments
Brian Kotek's Gravatar A generic factory like this begs the question, why are you even using ColdSpring? There's no advantage. No capability for dependency resolution. No AOP. No remote proxies. This is definitely a bad idea.

Is there a reason why you don't just define ColdFusion mappings so that your local, stage and produciton CFC paths are the same? Otherwise, having ANT replace the values in the config file is a valid option.
# Posted By Brian Kotek | 17/08/07 23:12
Daniel Lancelot's Gravatar @Brian:

Yeah - I had thought that it might be possible to use the depenency resolution etc. with the bean that is the result of calling the factory method? I can see though that it does feel like I'm negating a lot of the benefits of using CS.

Mappings can be (and are) identical between local and live. Staging however is often on the same server as live (we are talking multiple apps per server for most stuff here - no dedicated staging servers) - so mappings need to be different.

Im torn between using ANT - and moving the CFC's under the web root... (App specific mappings would be nice - but we're stuck on CF7 for the forseeable future...)
# Posted By Daniel Lancelot | 17/08/07 23:44
BlogCFC was created by Raymond Camden. This blog is running version 5.5.1, hosted by TalkWebSolutions.