Rob,
The other responses to your question, pretty much covered the auto-
wiring options. One additional option if you have CS Beans that
aren't singleton's but may see heavy use on certain requests is to
set the 'lazy-init="true"' value in your Bean XML . Doing this only
instantiates the bean when it is called from the bean factory but
doesn't throw it away once it's done being used.
The way I handle "lazy-init" beans is from a method within my
Controller.cfc called "needBean". It looks like this:
<cffunction name="needBean" access="public" returntype="void"
hint="I place a bean into the variables scope of the controller">
<cfargument name="bean" required="true"/>
<cfset variables.beans[arguments.bean] = getModelGlue().getBean
(arguments.bean) />
</cffunction>
You can always call a lazy-init bean directly from within the
function, but the "needBean" function allows you to instantiate it
from from the broadcasts which keeps your controller methods from
having to worry about bean scoping.
It also helps to pass framework into the bean as a constructor
argument in the Coldspring XML:
<bean id="userService" lazy-init="true" class="model.userService">
<constructor-arg name="framework">
<ref bean="ModelGlue"/>
</constructor-arg>
</bean>
Then your beans can call other beans if they are not auto-wired.
Regards,
Jon
On Feb 28, 2007, at 5:39 AM, Robert Rawlins wrote:
> Hey Guys,
>
> I'm looking for a few tips on whether I should be using ColdSpring
> to inject beans into my Controller class, my fear is that if I have
> a whole bunch of setter methods inside my controller layer, with
> every call to my controller CS will push in a load of new bean
> instances and we're going to end up with performance problems, is
> that right?
>
> I would be very interested to hear how you guys deal with
> instanstation inside your controller methods for beans in the model
> layer.
>
> Whilst we're talking performance and ColdSpring, maybe you could
> explain the deal with the Auto-Wire feature, should I, as a 'best
> practice' be hand coding the bean relationships rather than relying
> on the autowire feature to be doing it for me? how much longer does
> it take CS to calculate its autowire relationships.
>
> Many thanks,
>
> Rob
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
ColdFusion MX7 by AdobeĀ®
Dyncamically transform webcontent into Adobe PDF with new ColdFusion MX7.
Free Trial. http://www.adobe.com/products/coldfusion
Archive:
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:271019
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4