On Mar 14, 2006, at 9:22 PM, Troy Simpson wrote:
In order to make the mach-ii framework load faster, I would like to
only create an instance of an application object (like
securityService) on the first call and not when the framework is
loaded. I thought I saw something in ColdSpring called "lazy-load".
Can ColdSpring be configured to only load a component when it is first
called and not during the Mach-ii framework initialization?
Well, ColdSpring's default behavior is lazy-load, so it will not
create any objects until they are requested from the factory. Of
course, as you point out, everything will get created on application
startup if it is autowired to your mach-ii components. You could
certainly wire up the services the way you earlier suggested, call
getProperty( [beanFacotory] ) in your listeners, filters, plugins to
retrieve the beanFactory, then call getBean( [bean] ) to retrieve
your services when you need them. Just be sure to lock your variables
scope in your listeners when you retrieve your services. You need to
check if the service exists outside and inside the lock, to be
completely tread safe as well:
<cfif not StructKeyExists(variables, 'myService')>
<cflock name="someUniqueLockName" timout="10">
<cfif not StructKeyExists(variables, 'myService')>
<cfset variables.myService =
variables.bf.getBean('myService') />
</cfif>
</cflock>
</cfif>
That assumes you retrieved the beanFactory into variables.bf, in your
config method would be good.
However, now that I said all that, personally, I wouldn't do it.
What's so bad about the cost of firing up all of your service
components when your app loads? Really that will barely ever happen
once your app goes into production. If you find yourself constantly
reloading your app in development, try testing your services by
themselves in cfcUnit tests before integrating them into your app.
Then keep these as part of a test harness. It takes some more time up
front, but you will see the payoff soon, believe me.
Troy