You guys are awsome, and like I was saying I won't go about putting this practice into production, it's just how I like to learn. I go down a path untill I find the end then start another. The info that Sean gave me will definetly give me something to explore and in the process learn a lot about coldsprings capabilities.

Thanks again.

On 3/9/06, Dave Ross <[EMAIL PROTECTED]> 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