Thanks Brian
I failed to mention that these are my database cfcs which will often
change so application scope isn't the best choice for me. Even though
I'm not actually calling a database CRUD method yet, I wanted a handle
on the objects to grab later down in the page build. It's a small
application but every page request will be returning dynamic data.
Is there a lot more overhead instantiating an object versus say <cfparam
name="blah" default=""> ?
Brian Kotek wrote:
> 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?
>>
>>
>>
>>
>>
>>
>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Get the answers you are looking for on the ColdFusion Labs
Forum direct from active programmers and developers.
http://www.adobe.com/cfusion/webforums/forum/categories.cfm?forumid-72&catid=648
Archive:
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:288902
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4