Matt,

ColdSpring is best used to provide the larger infrastructure pieces of your application, so it'll build you up some nice sets of controllers amd service-layer objects and persistence objects... but when it comes to getting individual data-bearing objects, you're best bet is to have a ColdSpring-controlled service-layer object ask a ColdSpring-controlled constants object where to find User.cfc, then call createObject() itself. Otherwise you develop dependencies within your model on ColdSpring and start to work at cross-purposes with the whole framework.

Example:
<bean id="constants" class="some.path.to.constants">
<property name="BeanStore">
<value>some.path.</value>
</property>
<property name="DbMode">
<value>dev</value>
</property>
<property name="foo">
<value>bar</value>
</property>
</bean>
<bean id="UserService" >
<constructor-arg name="constants"><ref bean="constants /></constructor-arg>
</bean>

-- in userService.cfc (pseudo-code)--

<cffunction getUser()>
... query, calls, whatever ...
<cfreturn createObject("component",getConstants().getValue("beanstore") & "User").init(someData)>
</cffunction>

/Example


This may not be the best example, but it was handy in my head... it shows the idea of using ColdSpring to set up your applications infrastructure and using your objects in a modular way, but not creating dependencies on ColdSpring from within your model... because UserService relies on Constants, but neither of them explicity rely on ColdSpring you have a nice, abstracted way of getting each object to the right place but neither of them call ColdSpring directly and the User still gets created.


I hope that helps... if you need clarification just say the word. :)


Laterz,

J

------------------------------------------------

Jared C. Rypka-Hauer

Continuum Media Group LLC

http://www.web-relevant.com

Member, Team Macromedia - ColdFusion


"That which does not kill me makes me stranger." - Yonah Schmeidler


On Mar 23, 2006, at 1:18 PM, Matt Williams 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


Reply via email to