I've searched all over, and the "best" reason I could find is that
CFCs shouldn't be accessing anything outside of the CFC, hence
breaking encapsulation. If that's the case, then can someone provide
a concrete example where if I did access an application variable in a
CFC, then all hell would break loose? Most best practices have some
good logical reason behind them, which is all good and dandy, but this
particular one seems to fall in the category of "you should follow
this, but there are much worse things that can happen." Please
advise. Thanks
application.cfm
...
<cfset request.db_variable="my_sql_db">
...
OOB.cfc
...
<cfquery name="incaspulated_qry" datasource="#request.db_variable#">
...
I found out that rather than using an application variable, people
just pass the variable via an argument to the CFC. Seems kinda
kludgy, but I guess that might be my only option.
Putting the dsn in the request scope is interesting. I've never seen
it done that way before. What's the motivation behind that, out of
curiosity?
why don't you pass the application variable to the cfc as an argument
instead of accessing it directly in cfc? or if it's something like
datasource value create a this variable in the cfc and initialize
value through/in an init function.
http://www.coldfusionjedi.com/index.cfm/2007/6/22/Find-the-bug
See the comment by me (simplico).
Hope this helps!