Ahh, Pete, Sean, Dave...

I'm not sure who Ahh is, but he seems smart. 

But, good advice... I don't know why I didn't consider this before. I feel really dumb atm. ;) I mean, adding one get/set pair to the service object and an entry or two in the CS XML file would have solved my issue entirely.

What's the line from I, Robot? Something like: "... and you're the DUMBEST smart person I've ever met!"

That'd be me, at least today.

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 9, 2006, at 5:57 PM, Dave Ross wrote:

Spring has a BeanFactoryAware interface that, when implemented by a
Spring-managed bean, will cause the BeanFactory to inject itself into
the bean it's creating (you must implement a setBeanFactory(...)
method). We haven't done anything similar in ColdSpring, but this
blurb from the Spring docs might give you an idea why:

"While there are cases when this capability is useful, it should
generally be avoided, since it couples the code to Spring, and does
not follow the Inversion of Control style, where collaborators are
provided to beans as properties."

-Dave


On 3/9/06, Sean Corfield <[EMAIL PROTECTED]> wrote:
On 3/9/06, Paul Roe <[EMAIL PROTECTED]> wrote:
Based on your responses I'm left with the conclusion that it doesn't matter
if what I'm trying to do is possible or not, I just shouldn't do it.  Right
now I am just experimenting with this framework, getting to know it if you
will. It is good to learn these best practices that you all are providing,
however, I guess my real question is still left unanswered. Is this
possible, without hacking the framework?

Well, it's not how the framework is designed to be used so it is
deliberately non-trivial to make it work the way you are trying to do
it.

I can think of several ways to achieve what you want that bend the
framework to greater or lesser degrees.

First off, let me just reiterate that you should not be trying to have
your business object use the factory to get other objects -- you
should tell ColdSpring how to inject those other objects directly into
your business object.

Having said that, let's look at ways to solve your problem.

1. Add a setter to your business object, setBeanFactory(), and call it
directly in your application once you've asked ColdSpring for that
business object:

   busObj = application.cs.getBean("busy");
   busObj.setBeanFactory(application.cs);

2. Create a wrapper for the bean factory first. Declare a factory
object in cs.xml with a type factorywrapper.cfc - that CFC just has
set/get-BeanFactory() methods. Have your application ask ColdSpring
for the wrapper at startup and then call the setBeanFactory() method
(essentially as above). Declare all your business object to take a
wrapper as the constructor-arg (which is now a managed object so CS
*can* find it). The business object can then call its own
getBeanFactory().getBean("whatever") to get new beans:

   wrapper = application.cs.getBean("factory");
   wrapper.setBeanFactory(application.cs);

Then:

   busObj = application.cs.getBean("busy");

There may be other similar variants.

In other words, the application is the only part that knows about
ColdSpring directly.

Finally, this is not how Spring / ColdSpring was designed to be used
and you shouldn't be doing it this way.
--
Sean A Corfield -- http://corfield.org/
Got frameworks?

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood




Reply via email to