Duncan,

what you want to do is instantiate the cfc, rather than invoke it, if you
want to use it multiple times within a request. I wouldn't do that in
Application.cfm. It generally doesn't take very much time to instantiate a
cfc.

So instead of using cfinvoke, do it like this:

<cfset myObj = CreateObject('component','someMapping.Object').init() />

myObj then becomes an instance of Object.

Then you can call a method in your object multiple times within the request,
like so:

<cfset myResult = myObj.myMethod() />

Generally, developers are placing an init() method in their CFC's as a best
practice and calling it when they create an object to properly initialize it
with any variables your object needs to function properly. An example would
be, perhaps, a dsn.

<cfset myObjDAO =
createObject('component','someMapping.ObjectDAO').init(request.dsn) />

<cfcomponent displayName="ObjectDAO" hint="Lucky me, I'm a data access
object!" output="false">

        <cffunction name="init" access="public" 
returntype="someMapping.ObjectDAO"
output="false">
                <cfargument name="dsn" type="string" required="Yes" />
                <cfset variables.dsn = arguments.dsn />
                <cfreturn this />
        </cffunction>
....

</cfcomponent>

There are a few ways to go with organizing your CFC's . I prefer using
mappings. If you haven't used them yet - it's pretty straightforward. You
log into CF Admin, find the mapping link, and add a mapping to a physical
path. Then CFAS can find your CFC from anywhere in your application. In the
example above, i've used "someMapping".

If you're using a webhost, you want one that makes it easy to set up
mappings.

ciao,
Nando


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Behalf Of Duncan
Sent: Wednesday, March 09, 2005 3:46 AM
To: [email protected]
Subject: [CFCDev] cfc organisation


Hi everyone,

I am just trying to get to grips with CFC's and I just took one of our
CustomTags from a CF4.5 app and made it in to a CFC for a v7 app.

First of all may I say how easy it was to make it. Just brilliant.

The cfc in question takes a struct (like attributes) and converts all
the key value pairs in it to a URL of Form hidden fields format for
easy inclusion in a href or form.  You can specify exceptions that
dont get converted as well.

Now this could get used 3 or 4 times in a request and I was wondering
if I can invoke it once and then call upon the method as and when I
need it, but with different variables. Maybe chuck it in at
application start then use it during a request?

Second, I was wondering about how to 'file' my CFC's (I think the
number of them will grow very rapidly now I have done 1!).  A lot of
them will be used in different apps around my organisation and would
probably need to be shared across server instances too.  Any
suggestions on how to best acheive this?

Thanks in advance!


--
Duncan I Loxton
www.mcgrath.com.au
www.sixfive.co.uk
[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