Vince,

Requests only last as long as the request, so they will be fully
instantiated each and every time regardless of a check to see if they
exist or not.

Secondly I read that your DB constantly changes, then I sugest you
look at reactor and transfer and see how they handle it. The reason
being is that in production you DO NOT want to keep reinstantiating,
so your code should be relfecting changes as needed and test in that
manner, now and not later.


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?
>
>
>
>
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Enterprise web applications, build robust, secure 
scalable apps today - Try it now ColdFusion Today
ColdFusion 8 beta - Build next generation apps

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:288927
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to