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