Well, you're creating the CFCs over and over on every single request, which
is probably not good. Depending on what the CFCs do, and whether they are
stateless (have no changing instance data) or stateful (holds changing
instance data, or holds different instance data for each user), most people
store stateless instances in the application scope so they are only created
once during the lifetime of the application. Stateful CFC are harder to
store in the application scope since concurrency must be dealt with, and
"per-request" CFCs (CFCs that are unique to each user or to each request)
can't be easily kept in the application scope, and must be created for each
request or possibly stored in the session scope.
On 9/20/07, Vince Collins <[EMAIL PROTECTED]> wrote:
>
> While building my first app using CFCs yesterday, I found it easier for
> me to do a test for the existence of an object and if not found,
> instantiate it within Application.cfm like this.
>
> <cfif NOT isDefined("request.dsn")>
> <cfset request.dsn = "mydatabase" />
> </cfif>
>
> <cfif NOT isDefined("request.inventory")>
> <cfset request.inventory = createObject("component",
> "cfcs.inventory").init(request.dsn) />
> </cfif>
> <cfif NOT isDefined("request.classes")>
> <cfset request.classes = createObject("component",
> "cfcs.classes").init(request.dsn) />
> </cfif>
> ...
> /application.cfm
>
>
>
> Each instantiation is calling a simple init() method within the class
> such as this one within inventory.cfc:
>
>
>
> <cfcomponent hint="Inventory Object">
> <cfset variables.dsn = "" />
> <cfset variables.inventory = "" />
>
> <cffunction name="init" access="public" returnType="inventory"
> output="false" hint="I instantiate qry">
> <cfargument name="dsn" type="string" required="yes" />
> <!--- initiate value(s) --->
> <cfset variables.dsn = arguments.dsn />
> <cfset variables.inventory = "none" />
> <cfreturn this />
> </cffunction>
> (there are more methods within this cfc but I'm leaving them out to make
> this easier to read.)
> </cfcomponent>
>
>
>
> My thought here is that I will always have access to the instantiated
> objects without having to test for their existence. However, since I'm
> not completely familiar with how this all works, Am I creating large
> amounts of overhead to the server for this convenience? I wouldn't
> think so since I'm not calling any major methods yet but maybe there is
> more going on?
>
>
>
>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Download the latest ColdFusion 8 utilities including Report Builder,
plug-ins for Eclipse and Dreamweaver updates.
http;//www.adobe.com/cfusion/entitlement/index.cfm?e=labs%5adobecf8%5Fbeta
Archive:
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:288898
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4