Stephen,

One thing that I've found invaluable when working with persistant CFCs is the use of the Memento pattern.  Mementos allow you to save and restore the CFC's internal state after reloading the CFC code from disk. 

For instance, let's say you're working with a persistant ShoppingCart CFC and the feature you're trying to test is only available during checkout.  If you clear the entire session scope (or even just replace the persistant object with a new one) you'll have to manually re-build your cart and re-enter checkout before you can test the new feature.  However, if you have a way of reloading the CFC code *without* losing its internal state it becomes much easier to test your changes.

It works kind of like this:

<cfif isDefined("url.reloadCartCFC")>
<!--- make a record of the current cart data --->
<cfset cartMemento = session.ShoppingCart.getState ()>

<!--- create a new cart object using the updated CFC --->
<cfset session.ShoppingCart = CreateObject("component", "ShoppingCart").init()>

<!--- now load the saved state back into the cart --->
<cfset session.shoppingCart.setState(cartMemento)>
</cfif>

At their simplest form the get/setState() methods set and read a struct containing the internal state of the shopping cart.  Google for Memento pattern for more info.

Seth

On 1/12/06, Baz <[EMAIL PROTECTED]> wrote:

Stephen,

 

You seem to be doing it right. Your only problem is when the CFC code changes, which wouldn't really happen in a production environment. So in my development environment I check for the URL var "reset" and re-initialize all session vars if it exists so I don't have to keep restarting the server.

 

<cfif isDefined('url.reset')>

            <cfscript>

                        StructClear(session);

                        StructClear(application);

                        onApplicationStart();

                        onSessionStart();

            </cfscript>

</cfif>

 

Baz

 

 


From: [EMAIL PROTECTED] [mailto: [EMAIL PROTECTED]] On Behalf Of Stephen Adams
Sent: Thursday, January 12, 2006 11:16 AM
To: [email protected]
Subject: [CFCDev] making objects accessible in multiple pages

 

Hi,

I've just created my first Object Factory (which I'm very proud of), I've set the returned object in a session variable so that it it available in multiple pages, especially the data access object I've created. One problem I've found is that when I make a change to the cfc, these changes are not reflected.
I closed the browser, as I'd hoped that it would clear the session variable, but that did not work. Eventually I had to restart ColdFusion to clear the object.
What's the best way to create an object, which you'd like to be accessible in multiple pages?

Stephen
----------------------------------------------------------
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).

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

----------------------------------------------------------
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).

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

----------------------------------------------------------
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).

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

Reply via email to