Okay Ken, that makes sense. I do have a PersonDAO. It doesn't depend on anything other than the DSN. Nor does my PersonGateway. I guess it makes more sense to me that my PersonService should be the only object that has all the dependencies (PersonBean, PersonDAO, PersonGateway). It also sounds like, from what you wrote, that even if I did do this via my DAO, I would still have to use createObject within the Read method.
 
And yes, so far as I build this, anytime I need that PersonBean, I call on the PersonService for it.
 
Thanks for your help. For now, I'll try the createObject deal.
 
Interesting note on how I found this problem though. I'm using Mach-II. When I have the app reloading everytime this isn't an issue as the PersonBean gets re-injected, automatically creating my new instance for me. When I swtiched off the reloading, I started getting wierd results. It took me a while to realize what was going on.


From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Ken Dunnington
Sent: Thursday, March 23, 2006 12:38 PM
To: [email protected]
Subject: [coldspring-dev] Bean and Singleton

Matt -

I had the same idea awhile ago, I wanted to have CS use Reactor's createRecord() method as a factory-method, but this is really not what ColdSpring is meant for. Your service shouldn't "depend" on the bean that it's meant to create, but it should depend on a factory that can create the Person bean for it. So, assuming you aren't going to use a DAO, it's perfectly legitimate for your PersonService to use createObject to make a PersonBean. I would personally (ha) recommend using a DAO for this purpose, but it's up to you really. The important part is that any other part of your application that would need Person beans should be wired to the PersonService in CS.

- Ken

On 3/23/06, Matt Williams <[EMAIL PROTECTED]> wrote:
Not sure how to explain my issue...

My ColdSpring.xml file defines the PersonBean (basic getter/setter
bean). I have a PersonService.cfc that has a setPersonBean method. So CS
injects the PersonBean into the PersonService. In another method in the
PersonService, called 'getPerson', I want to create a new instance of
the PersonBean each time it is run.

How do I do this?

I thought setting singleton="true" on the PersonBean definition might do
it, but it doesn't. Probably because PersonService itself is a
singleton.

Okay, so I just tested this and I can set the PersonService to not be a
singleton, and I get what I want. But in my mind, the PersonService
should be a singleton, but the PersonBean should be created new each
time (I want a new instance as I am putting the PersonBean into an array
as they are created).

Maybe I'm going about it all wrong. I can also get it to work if I don't
use the injected bean, and simply do a createObject call in the
getPerson method.

But is there a better way? Thoughts?

Thanks, Matt Williams




--
Quidquid latine dictum sit, altum sonatur.
- Whatever is said in Latin sounds profound.

Reply via email to