On Thu, Dec 2, 2010 at 9:36 PM, Gavin Baumanis <be...@palcare.com.au> wrote:
> * my question is upon the next method call of "mybean" (In a
> completely separate request;
> <cfset myOtherResult =
> application.beanfactory.getbean('mybean').myOtherMethod() />
> - is the object recreated or is it actually "within" the factory - in
> this case in the application scope.
ALL invocations of getBean("myBean") will return the same CFC instance
for the life of the beanFactory. That's what it means to be a
singleton.
> * If for "whatever" reason I created the beanfactory in the session
> scope - does that mean that my singleton objects are effectively
> session scoped too?
Yep, your singletons will be session scoped for the same reason as
above: singletons have exactly one instance for the life of the
beanFactory.
> * would I "ever" need to do something like this?;
> <cfset application.myCFCName =
> application.beanfactory.getbean('mybean') >
>
> and then use application.myCFCName - as if I had created the object
> myself using CF's createObject function.
> <cfset myLastResult = application.myCFCName.myMethod() />
No, there's never a compelling reason to do that. Using an external
variable can reduce verbosity and it avoids the repeated invocations
of getBean, but there isn't any "real" benefit of an external
variable. I frequently do <cfset myObj =
application.beanFactory.getBean("myNeatSingletonObject") /> at the top
of my controllers so I can just do myObj.neatMethod(), which is a lot
easier to read.
> * and If I did the above - have I actually just gone and created a new
> instance of the class?
Nope, you've just created an additional reference to the SAME instance
of your CFC.
cheers,
barneyb
--
Barney Boisvert
bboi...@gmail.com
http://www.barneyb.com/
The only reason I can suggest is performance: ColdSpring 1.x has some
overhead in getBean() and you _can_ (sometimes) get a performance
improvement by keeping direct references to the CFC instances that
ColdSpring creates. But I really wouldn't recommend it. As Barney
says, application.beanFactory.getBean('mybean') will always return the
same instance and that should be all you'll need.
--
Sean A Corfield -- (904) 302-SEAN
Railo Technologies, Inc. -- http://getrailo.com/
An Architect's View -- http://corfield.org/
"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood