Yes, but why are you creating a copy in the first place? Why do you think
you need a copy and not a reference?

On 10/29/07, Ryan Heldt <[EMAIL PROTECTED]> wrote:
>
> Thanks everyone for responding. Unfortunately, the method suggested by
> Rich
> below seemed to create a pointer rather than a separate instance of the
> object, as I had hoped. However, after discussing this with a co-worker,
> we
> seem to have cooked-up a viable solution.
>
> There were two objects I wanted to "copy" into the request scope. So, in
> each of those objects, we added a copy() constructor that took the initial
> object, then copied all of the properties over, for instance:
>
> <cffunction name="copy" access="public" output="false"
> returntype="AuthenticatedUser">
>         <cfargument name="object" type="AuthenticatedUser" required="true"
> />
>         <cfscript>
>                 _userID = object.getUserID();
>                 _username = object.getUsername();
>                 _firstName = object.getFirstName();
>                 _lastName = object.getLastName();
>                 _email = object.getEmail();
>                 _permissions = object.getPermissions();
>                 _isAuthenticated = object.getIsAuthenticated();
>         </cfscript>
>         <cfreturn this />
> </cffunction>
>
> Then, in Application.cfc, onRequestStart():
>
> <!--- Copy AuthenticatedUser object over to request scope --->
> <cflock timeout="10" throwontimeout="false" type="readonly"
> scope="session">
>         <cfset request.myAuthenticatedUser =
> createObject("component","AuthenticatedUser").copy(
> session.myAuthenticatedUs
> er) />
> </cflock>
>
> Thanks!
> Ryan
>
> > -----Original Message-----
> > From: Rich [mailto:[EMAIL PROTECTED]
> > Sent: Monday, October 29, 2007 12:40 PM
> > To: CF-Talk
> > Subject: RE: Copying a CFC Persisted in Session Scope
> >
> > > I realize this topic may have been covered on this list a
> > while back,
> > > but I'm having problems locating a good answer, so here goes.
> > > Typically in our administrative web sites, on a request, we
> > copy over
> > > our session variables to the request scope so we can have
> > read-access
> > > to the information without having to place locks all over the place.
> >
> > I would suggest that you create a Session Facade and then
> > have all your objects reference the façade.  It is generally
> > a bad idea to have an object reference an external scope
> > (session, request, etc.), and this technique hides the
> > implementation from your business objects.
> >
> > Assuming you wanted to return an 'admin' object, your objects
> > would use a
> > sessionFaçade.getAdminObject() and the function within the
> > façade would look like the following (excluding locks, etc.
> > for the sake of simplicity):
> >
> > function getAdminObject() {
> >       Return session.adminObject
> > }
> >
> > HTH,
> > Rich Kroll
> >
> >
> >
>
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
ColdFusion is delivering applications solutions at at top companies 
around the world in government.  Find out how and where now
http://www.adobe.com/cfusion/showcase/index.cfm?event=finder&productID=1522&loc=en_us

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:292265
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