Orange is my favorite color

A quick tip, whose example will be based on TransferSync, the ColdFusion event gateway that keeps multiple Transfer ORM nodes in a cluster synchronized. Whenever you incorporate third party libraries, you run the risk of having to customize them for your environment. With TransferSync, for example, you need to give the library a reference to your Transfer instance. The project used to ship with a reference like so:

<cfcomponent>

  
  <cfset this.transfer = application.transfer />
  <cfset this.gatewayName = 'TransferSync_appName' />

  ...
</cfcomponent>

So long as you also have an application.transfer variable, you were set. I, however, have my ORMservice defined in Coldspring and cached as application.cs. So I would need to modify the gateway/jms/transferSync/TransferSync.cfc file to look like:

<cfset this.transfer = application.cs.getBean('ormService').getTransfer() />

That’s fine. Except every time Tom updates TransferSync, I have to remember to propagate this change to or else I will break my system. That’s a bummer. But it’s also an opportunity for CFC inheritance to work a little magic. In the latest 0.5 release, I convinced Tom to make the default variable assignment empty:

<cfset this.transfer = '' />

That means, out of the box, the code isn’t going to work but it also isn’t going to throw an error when it fires up and can’t find application.tranfer. Given how many ways people define their Transfer instance, the reality is most users would need to modify the code anyways. Instead, with this change I can now create a CFC in my application that extends the TransferSync.cfc and configure it for my environment like so:

<cfcomponent output="false" extends="coreapi.transfersync.gateway.jms.transferSync.TransferSync">
	<cfset this.transfer = application.cs.getBean('ormService').getTransfer() />
	<cfset this.gatewayName = 'TransferSync_PukkaCore' />
</cfcomponent>

Awesome. Now assuming no configuration changes to TransferSync, I can happily rely on a Subversion Externals that points to the most up-to-date underlying TransferSync library and completely separate my configuration from Tom’s code.

Comments are closed.