Best Wishes,
Peter
Bear in mind this is a one-time thing as well--iow you should be
instantiating your service in your listener when it first gets
created, and in turn your dao and gateway get instantiated in your
service, but only once. Let me know if that doesn't make sense.
--
Matt Woodward
mpwoo...@gmail.com
http://www.mattwoodward.com
Just curious why moving these objects across projects would be so
bad--as long as you're consistent it should just work, you'd just have
to remember to have the dsns in your application scope.
All this being said I don't do this myself, and I'd strongly, strongly
suggest getting on ColdSpring as soon as possible, but in the interim
this doesn't seem like such a horrendously bad approach to me.
--
When we create an object, we inject that variable via init():
<cffunction name="init">
<cfargument name="DSN" type="struct" required="true" />
<cfset variables.DSN = arguments.DSN />
<cfreturn this />
</cffunction>
<cfset myCFC = createObject("component", "path.to.MyCFC").init( DSN =
application.DSN ) />
Then we can call whichever DSN we need inside the CFC:
<cffunction name="getSomeData" returntype="query">
<cfset var foo = "" />
<cfquery name="foo" datasource="#variables.DSN.dsn_a#">
...
</cfquery>
<cfreturn foo />
</cffunction>
This has worked extremely well for us. When we started our site redesign
project, we were in the same boat re ColdSpring. We had a hard enough
time getting OOP concepts accepted by parts of the team that had never
programmed like that before, plus CS hadn't released version 1.0 yet.
I will recommend that if you're not going to use ColdSpring, look into
Object Factories. You'll get the benefits of CS without learning a new
framework.
I couldn't really begin to describe why we have so many data sources,
but it's been interesting, let me tell you. :)
-- Adrian
Reason this gets harder for object reuse is that it's a slippery slope. Just
wait until you have 60 projects with beans from each relying on a different
subset of 200 application variables - it becomes a real pain to handle the
"which properties are required by which bean in which application" stuff.
The reason (for me) to avoid application scope is that you're creating
undocumented dependencies within the bean and the more of those you have,
the more likely you are to run into issues when re-using the beans.
That said, in this case, it's what I'd do if I wasn't using ColdSpring or
something similar.
Best Wishes,
Peter