RE: Session Variables in CFCs

2004-02-11 Thread Barney Boisvert
If you have a fully encapsulated CFC it should be unaware of it's
environment in any way.Since the session scope is part of the CF
environment, CFCs shouldn't know about it.Generally the better route is to
put the entire CFC in the session scope, and have the CFC only manupulate
instance variable (which are also in the session scope, because the whole
CFC is).That way the CFC doesn't need to know about the various CF scopes.
This same thing applies to the application and server scopes as well.

Now, not every CFC is fully encapsulated.If you have a CFC who's task is
to manage authentication, it's almost required to set session (or client)
variables.The difference is that this CFC is setting the session variables
for OTHER CODE to make use of (possibly CFCs, possibly not).It's not
setting them for IT'S INTERNAL USE.

Obviously that's a gross oversimplification of the whole situation, but
hopefully helps.

Cheers,
barneyb

 -Original Message-
 From: Merritt Chapman [mailto:[EMAIL PROTECTED] 
 Sent: Wednesday, February 11, 2004 8:36 AM
 To: CF-Talk
 Subject: Re:Session Variables in CFCs
 
 Nathan,
 
 I'm running CFMX 6.1 Enterprise.Are you saying that 
 declaring session variables within CFCs is bad architecture?
 If so, please explain.Also, for my own use, could you give 
 me an example of a session variable declaration that should 
 work within a CFC?
 
 Thanks again!
 MC

 [Todays Threads] 
 [This Message] 
 [Subscription] 
 [Fast Unsubscribe] 
 [User Settings]




RE: Session Variables in CFCs

2004-02-11 Thread Nathan Strutz
Thanks Barney,

To continue on what you said, not every CFC is fully encapsulated, this is
using a CFC as more of a function library than an object in an OO world. Not
best practices as far as OO methods go, but still a fair use for a CFC
just to abstract a certain job.

Back to Merritt, I can easily set a session variable in a CFC just using
cfset session.foo = bar. I'll send you some sample code if you need to
see it work.

-nathan

-Original Message-
From: Barney Boisvert [mailto:[EMAIL PROTECTED]
Sent: Wednesday, February 11, 2004 11:02 AM
To: CF-Talk
Subject: RE: Session Variables in CFCs

If you have a fully encapsulated CFC it should be unaware of it's
environment in any way.Since the session scope is part of the CF
environment, CFCs shouldn't know about it.Generally the better route is
to
put the entire CFC in the session scope, and have the CFC only manupulate
instance variable (which are also in the session scope, because the whole
CFC is).That way the CFC doesn't need to know about the various CF
scopes.
This same thing applies to the application and server scopes as well.

Now, not every CFC is fully encapsulated.If you have a CFC who's task is
to manage authentication, it's almost required to set session (or client)
variables.The difference is that this CFC is setting the session
variables
for OTHER CODE to make use of (possibly CFCs, possibly not).It's not
setting them for IT'S INTERNAL USE.

Obviously that's a gross oversimplification of the whole situation, but
hopefully helps.

Cheers,
barneyb

 -Original Message-
 From: Merritt Chapman [mailto:[EMAIL PROTECTED]
 Sent: Wednesday, February 11, 2004 8:36 AM
 To: CF-Talk
 Subject: Re:Session Variables in CFCs

 Nathan,

 I'm running CFMX 6.1 Enterprise.Are you saying that
 declaring session variables within CFCs is bad architecture?
 If so, please explain.Also, for my own use, could you give
 me an example of a session variable declaration that should
 work within a CFC?

 Thanks again!
 MC

 [Todays Threads] 
 [This Message] 
 [Subscription] 
 [Fast Unsubscribe] 
 [User Settings]




RE: Session Variables in CFCs

2004-02-11 Thread Barney Boisvert
You're exactly right with the function library thing.Definitely not good
OO technique, but with CFCs the lines are blurred.I had similar text in
there almost verbatim, but took it back out.

For instance, simple CFC-based web services are necessarily of this nature.
Extracting reusable bits and pieces our of non-OO CF app into CFCs as a
first step is another prime example (and one that I've used with great
success when working with a couple large apps that we moved from CF4.5 to
CFMX last year).

Cheers,
barneyb

 -Original Message-
 From: Nathan Strutz [mailto:[EMAIL PROTECTED] 
 Sent: Wednesday, February 11, 2004 10:17 AM
 To: CF-Talk
 Subject: RE: Session Variables in CFCs
 
 Thanks Barney,
 
 To continue on what you said, not every CFC is fully 
 encapsulated, this is
 using a CFC as more of a function library than an object in 
 an OO world. Not
 best practices as far as OO methods go, but still a fair 
 use for a CFC
 just to abstract a certain job.
 
 Back to Merritt, I can easily set a session variable in a CFC 
 just using
 cfset session.foo = bar. I'll send you some sample code 
 if you need to
 see it work.
 
 -nathan
 
 
-Original Message-
From: Barney Boisvert [mailto:[EMAIL PROTECTED]
Sent: Wednesday, February 11, 2004 11:02 AM
To: CF-Talk
Subject: RE: Session Variables in CFCs
 
 
If you have a fully encapsulated CFC it should be unaware of it's
environment in any way.Since the session scope is part of the CF
environment, CFCs shouldn't know about it.Generally the 
 better route is
 to
put the entire CFC in the session scope, and have the CFC 
 only manupulate
instance variable (which are also in the session scope, 
 because the whole
CFC is).That way the CFC doesn't need to know about the various CF
 scopes.
This same thing applies to the application and server 
 scopes as well.
 
Now, not every CFC is fully encapsulated.If you have a 
 CFC who's task is
to manage authentication, it's almost required to set 
 session (or client)
variables.The difference is that this CFC is setting the session
 variables
for OTHER CODE to make use of (possibly CFCs, possibly 
 not).It's not
setting them for IT'S INTERNAL USE.
 
Obviously that's a gross oversimplification of the whole 
 situation, but
hopefully helps.
 
Cheers,
barneyb
 [Todays Threads] 
 [This Message] 
 [Subscription] 
 [Fast Unsubscribe] 
 [User Settings]




RE: Session Variables in CFCs

2004-02-10 Thread Nathan Strutz
In CFMX 6.0, you will have this problem. Upgrade to 6.1 to make it work. 6.0
could not read/write to any persistant scope by design. However, this
behavior was changed in 6.1 to allow this. Another related change is that
CFCs can no longer write to the variables scope on the page they are called
from. Besides the fact that this is bad architecture, you can still fully
access the request scope instead.

If this isn't the problem, just let us know and give us more details, if you
can.

Also, thanks to CFMX's java roots, you don't need an exclusive lock around
every session variable as you did in previous versions of coldfusion.

-nathan strutz

-Original Message-
From: Merritt Chapman [mailto:[EMAIL PROTECTED]
Sent: Tuesday, February 10, 2004 3:18 PM
To: CF-Talk
Subject: Session Variables in CFCs

Can someone give me an example of a session variable declaration within a
CFC that will persist throughout a session?

The following code does not seem to work right.The variable gets defined
but the value is always empty.What am I doing wrong?

cflock scope=session type=exclusive timeout=500
 cfset session.myVar = test
/cflock

I would like to have multiple CFCs that control a group of session level
IDs that determine the output in a dynamic user interface.Is there a
better way to do this with CFCs than to use session variables?

Thanks in advance!

-MC
 [Todays Threads] 
 [This Message] 
 [Subscription] 
 [Fast Unsubscribe] 
 [User Settings]