Mike, I believe in the example it is the role of the UserService to encapsulate the session mechanism itself (serving as a Session Facade). Something has to know about how sessions are handled in the application and that is the purpose of the UserService so it's okay for it to access the session scope. The idea is if the session mechanism were to change for some reason, you would (theoretically) only have to make the changes in one place (the UserService) and the rest of the application wouldn't know or care about the change. This design decision means the session scope becomes an internal concern for the UserService; it doesn't get passed in because no other object even knows about the session. The UserService can access the session directly, so it doesn't need to get that information anywhere else.
If it were the case that no CFC can ever access a shared scope, you wouldn't ever be able to use shared scopes in an application. You definitely want to minimize the number of CFCs that access shared scopes (and thus are affected by any changes you make to those scopes), so you build a single CFC that is responsible for that access and inject this "Facade" CFC into your other CFCs that are interested in that scope. Finally, to answer your previous question, I think the fact that you define the UserService in your ColdSpring config means you don't have to worry about instantiating it at all. ColdSpring will instantiate it for you and inject it into your other CFCs as necessary. I haven't actually used ColdSpring before, so I may be wrong here, but I'm pretty sure that's how it's meant to work. -Justin On 11/4/07, Mike Kear <[EMAIL PROTECTED]> wrote: > > Wait a minute! How can the UserService return the session.cacheduserbean, > if it's not passed into it? > > Once again, I thought it was a general rule-of-thumb that you never ask a > CFC to access a shared scope. That if a CFC needs to know something (in > this case the session.userbean) it's passed in. > > Now if I'm using coldspring to instantiate all CFCs, how do I persuade > ColdSpring to pass the session.userbean into the UserService? > > (I've gone round a full circle and I'm back where I started.) > > Cheers > Mike Kear > Windsor, NSW, Australia > 0422 985 585 > Adobe Certified Advanced ColdFusion Developer > AFP Webworks Pty Ltd > http://afpwebworks.com > Full Scale ColdFusion hosting from A$15/month > > > > -----Original Message----- > From: [email protected] > [mailto:[EMAIL PROTECTED] On Behalf Of Sean Corfield > Sent: Sunday, 4 November 2007 7:42 AM > > [snip] > > Here's how I would handle the audit trail. > > First off, I'd have a userService that has methods: isLoggedIn() and > getUser() that return true iff the user is logged in and the > session-cached user bean respectively. > > > [/snip] > > > > >
