Kerry,

Thanks for that, it took a few minutes of staring blankly but I clicked what you were saying in the end.

Cheers, Pete (aka lad4bear)



<br><br><br>----Original Message Follows----<br>From: &quot;Kerry&quot; &lt;[EMAIL PROTECTED]&gt;<br>Reply-To: [email protected]<br>To: &lt;[email protected]&gt;<br>Subject: RE: [CFCDev] Singleton / Factory request<br>Date: Thu, 12 May 2005 17:15:50 +0100<br><br> &gt;Any comments appreciated.<br><br>Why does the factory manager go back out of itself to application scope,<br>when it itself is already a singleton in application scope?<br><br>You could change to:<br><br>&lt;!--- Instantiate ComponentManager ---&gt;<br><br>&lt;cfif not StructKeyExists(Application, 'ComponentFactoryManager') &gt;<br> &lt;cflock name=&quot;LoadComponentFactoryManager&quot; timeout=&quot;10&quot; type=&quot;exclusive&quot;&gt;<br> &lt;cfif not structKeyExists( Application, 'ComponentFactoryManager' )&gt;<br> &lt;cfset Application.ComponentFactoryManager = CreateObject('Component',<br>'Components.ComponentFactoryManager') /&gt;<br> &lt;cfset Application.ComponentFactoryManager.init()&gt;<br> &lt;/cfif&gt;<br> &lt;/cflock&gt;<br>&lt;/cfif&gt;<br><br>In ComponentFactoryManager &lt;&lt;singleton&gt;&gt;<br><br>&lt;cfcomponent displayname=&quot;ComponentFactoryManager&quot;&gt;<br><br> &lt;cffunction name=&quot;init&quot;&gt;<br> &lt;cfset variables.instance = structnew()&gt;<br> &lt;cfset variables.instance.ComponentFactory = CreateObject('Component',<br>'Components.ComponentFactory') /&gt;<br> &lt;/cffunction&gt;<br><br> &lt;cffunction name=&quot;Instance&quot; access=&quot;public&quot; returntype=&quot;any&quot; output=&quot;false&quot;<br> &gt;<br> &lt;cfreturn variables.instance.ComponentFactory /&gt;<br> &lt;/cffunction&gt;<br><br>&lt;/cfcomponent&gt;<br><br>-----Original Message-----<br>From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]<br>Behalf Of Peter H<br>Sent: 12 May 2005 16:39<br>To: [email protected]<br>Subject: RE: [CFCDev] Singleton / Factory request<br><br><br>Thanks Nando,<br><br>I've ended up seperating the Singleton from the factory. Not sure if its the<br>best way though. Any comments appreciated.<br><br>Cheers, Pete (aka lad4bear)<br><br>In Application.cfc<br><br>&lt;!--- Instantiate ComponentManager ---&gt;<br>&lt;cfif not StructKeyExists(Application, 'ComponentFactoryManager') &gt;<br> &lt;cflock name=&quot;LoadComponentFactoryManager&quot; timeout=&quot;10&quot; type=&quot;exclusive&quot;&gt;<br> &lt;cfif not structKeyExists( Application, 'ComponentFactoryManager' )&gt;<br> &lt;cfset Application.ComponentFactoryManager = CreateObject('Component',<br>'Components.ComponentFactoryManager') /&gt;<br> &lt;/cfif&gt;<br> &lt;/cflock&gt;<br>&lt;/cfif&gt;<br><br>In ComponentFactoryManager &lt;&lt;singleton&gt;&gt;<br><br>&lt;cfcomponent displayname=&quot;ComponentFactoryManager&quot;&gt;<br><br> &lt;cffunction name=&quot;Instance&quot; access=&quot;public&quot; returntype=&quot;any&quot; output=&quot;false&quot;<br> &gt;<br> &lt;cfif not StructKeyExists(Application, 'ComponentFactory') &gt;<br> &lt;cflock name=&quot;LoadComponentFactory&quot; timeout=&quot;10&quot; type=&quot;exclusive&quot;&gt;<br> &lt;cfif not structKeyExists( Application, 'ComponentFactory' )&gt;<br> &lt;cfset Application.ComponentFactory = CreateObject('Component',<br>'Components.ComponentFactory') /&gt;<br> &lt;/cfif&gt;<br> &lt;/cflock&gt;<br> &lt;/cfif&gt;<br><br> &lt;cfreturn Application.ComponentFactory /&gt;<br> &lt;/cffunction&gt;<br><br>&lt;/cfcomponent&gt;<br><br>In ComponentFactory &lt;&lt;factory &gt;&gt;<br><br>&lt;cfcomponent displayname=&quot;ComponentFactory&quot; hint=&quot;&quot;&gt;<br><br> &lt;cffunction name=&quot;Create&quot; access=&quot;public&quot; returntype=&quot;any&quot; output=&quot;false&quot; &gt;<br> &lt;cfargument name=&quot;ComponentType&quot; type=&quot;string&quot; required=&quot;true&quot;&gt;<br> &lt;cfset var component = 0 /&gt;<br><br> &lt;cfswitch expression=&quot;#arguments.ComponentType#&quot;&gt;<br> &lt;cfcase value=&quot;PingRequest&quot;&gt;<br> &lt;cfset component = CreateObject('Component',<br>'Components.PingRequest').Init() /&gt;<br> &lt;/cfcase&gt;<br><br> &lt;cfcase value=&quot;OptionRequest&quot;&gt;<br> &lt;cfset component = CreateObject('Component',<br>'Components.OptionRequest').Init() /&gt;<br> &lt;/cfcase&gt;<br> &lt;/cfswitch&gt;<br><br> &lt;cfreturn component /&gt;<br> &lt;/cffunction&gt;<br><br>&lt;/cfcomponent&gt;<br><br><br><br><br><br><br>&lt;br&gt;&lt;br&gt;&lt;br&gt;----Original Message Follows----&lt;br&gt;From: &amp;quot;Nando&amp;quot;<br>&amp;lt;[EMAIL PROTECTED]&amp;gt;&lt;br&gt;Reply-To: [email protected]&lt;br&gt;To:<br>&amp;lt;[email protected]&amp;gt;&lt;br&gt;Subject: RE: [CFCDev] Singleton / Factory<br>request&lt;br&gt;Date: Thu, 12 May 2005 15:51:42 +0200&lt;br&gt;&lt;br&gt;&amp;lt;cfif NOT<br>StructKeyExists(application,&amp;quot;mySingleton&amp;quot;)&amp;gt;&lt;br&gt; &amp;lt;cflock<br>name=&amp;quot;mySingletonLock&amp;quot; Timeout=&amp;quot;10&amp;quot;<br>THROWONTIMEOUT=&amp;quot;No&amp;quot;&lt;br&gt;Type=&amp;quot;Exclusive&amp;quot;&amp;gt;&lt;br&gt;<br>&amp;lt;cfif NOT StructKeyExists(application,&amp;quot;mySingleton&amp;quot;)&amp;gt;&lt;br&gt;<br>&amp;lt;cfset application.mySingleton<br>=&lt;br&gt;CreateObject('component','Singleton').init(....)&amp;gt;&lt;br&gt;<br>&amp;lt;/cfif&amp;gt;&lt;br&gt; &amp;lt;/cflock&amp;gt;&lt;br&gt;&amp;lt;/cfif&amp;gt;&lt;br&gt;&lt;br&gt;Does that help?<br>The lock is necessary to be absolutely sure, because there's&lt;br&gt;a very small<br>time lag between the moment a request passes thru the first&lt;br&gt;cfif and the<br>moment application.mySingleton is created.&lt;br&gt;&lt;br&gt;n. :)&lt;br&gt; -----Original<br>Message-----&lt;br&gt; From: [EMAIL PROTECTED]<br>[mailto:[EMAIL PROTECTED] Behalf&lt;br&gt;Of Peter H&lt;br&gt; Sent:<br>Thursday, May 12, 2005 3:16 PM&lt;br&gt; To: [email protected]&lt;br&gt; Subject:<br>[CFCDev] Singleton / Factory request&lt;br&gt;&lt;br&gt;&lt;br&gt; Hi guys,&lt;br&gt;&lt;br&gt; I'm<br>trying to build a Singleton / Factory but seemed to have got myself<br>a&lt;br&gt;little tangled up. Here's what I'm trying to do.&lt;br&gt;&lt;br&gt; 1) Have a<br>factory component that is responsible for creating all of my&lt;br&gt;other<br>components by name.&lt;br&gt;&lt;br&gt; 2) Make this factory a singleton so that it's<br>only created once and stored&lt;br&gt;in application scope.&lt;br&gt;&lt;br&gt; I've heard<br>people talk about this on the board and was hoping someone&lt;br&gt;would post be<br>able to post some code for me to look at.&lt;br&gt;&lt;br&gt; Cheers, Pete (aka<br>lad4bear)&lt;br&gt;<br>----------------------------------------------------------&lt;br&gt; You are<br>subscribed to cfcdev. To unsubscribe, send an email to&lt;br&gt;[email protected]<br>with the words 'unsubscribe cfcdev' as the subject of the&lt;br&gt;email.&lt;br&gt;&lt;br&gt;<br> CFCDev is run by CFCZone (www.cfczone.org) and supported by<br>CFXHosting&lt;br&gt;(www.cfxhosting.com).&lt;br&gt;&lt;br&gt; CFCDev is supported by New<br>Atlanta, makers of BlueDragon&lt;br&gt;<br>http://www.newatlanta.com/products/bluedragon/index.cfm&lt;br&gt;&lt;br&gt; An archive<br>of the CFCDev list is available<br>at&lt;br&gt;www.mail-archive.com/[email protected]&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;---------------<br>-------------------------------------------&lt;br&gt;You<br>are subscribed to cfcdev. To unsubscribe, send an email to<br>[email protected] with the words 'unsubscribe cfcdev' as the subject of the<br>email.&lt;br&gt;&lt;br&gt;CFCDev is run by CFCZone (www.cfczone.org) and supported by<br>CFXHosting (www.cfxhosting.com).&lt;br&gt;&lt;br&gt;CFCDev is supported by New Atlanta,<br>makers of<br>BlueDragon&lt;br&gt;http://www.newatlanta.com/products/bluedragon/index.cfm&lt;br&gt;&lt;br<br> &gt;An<br>archive of the CFCDev list is available at<br>www.mail-archive.com/[email protected]&lt;br&gt;<br><br><br><br><br>----------------------------------------------------------<br>You are subscribed to cfcdev. To unsubscribe, send an email to<br>[email protected] with the words 'unsubscribe cfcdev' as the subject of the<br>email.<br><br>CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting<br>(www.cfxhosting.com).<br><br>CFCDev is supported by New Atlanta, makers of BlueDragon<br>http://www.newatlanta.com/products/bluedragon/index.cfm<br><br>An archive of the CFCDev list is available at<br>www.mail-archive.com/[email protected]<br><br><br><br><br><br>----------------------------------------------------------<br>You are subscribed to cfcdev. To unsubscribe, send an email to [email protected] with the words 'unsubscribe cfcdev' as the subject of the email.<br><br>CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting (www.cfxhosting.com).<br><br>CFCDev is supported by New Atlanta, makers of BlueDragon<br>http://www.newatlanta.com/products/bluedragon/index.cfm<br><br>An archive of the CFCDev list is available at www.mail-archive.com/[email protected]<br><br><br>




---------------------------------------------------------- You are subscribed to cfcdev. To unsubscribe, send an email to [email protected] with the words 'unsubscribe cfcdev' as the subject of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting 
(www.cfxhosting.com).

CFCDev is supported by New Atlanta, makers of BlueDragon
http://www.newatlanta.com/products/bluedragon/index.cfm

An archive of the CFCDev list is available at 
www.mail-archive.com/[email protected]




Reply via email to