Should components be initialized in the application? If so where? Is there a common factor on when and where a cfc should be initialized?
As an example, I have a news section that pages and I initiate the cfc like <cfset news_listings = new news.whatever()> as users page that is called over and over. Should that be moved to the application so its only initiated one time or is doing that perfectly fine?
yes, sure.
just put your components in the application scope.
<cfif NOT structKeyExists(application, "news_listings">
<cfset application.news_listings = new news.whatever()>
</cfif>
2 Likes
I think about things like…
Do I need “a” copy for each user / for each browser session?
Do I need “a” copy for each user, each request?
Can multiple users use the same CFC with the same data attached to it?
Those questrions normally lead me to the where do I instantiate this CFC (which scope) / which part of the request life-cycle and do I need caching?
2 Likes