Thanks for the insight, guys! I've got it up and running now with setter methods!
Jonathon _____ From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Jaime Metcher Sent: Monday, July 09, 2007 7:44 PM To: [email protected] Subject: [coldspring-dev] init-method usage Jonathon, init-method just lets you nominate some function to be run after the bean has been fully instantiated (i.e. after init() and any property setters). I don't think there's a way to pass any arguments to the init-method, so you couldn't use it to inject dependencies as you are trying to do. What Brian describes is step 3 in Peter Farell's description. The "magic" is that CS is looking at your properties and working out that it needs to call setArticleCFC() (aka setArticles() in Brian's example). You still need to write the setter function yourself. Jaime Metcher -----Original Message----- From: [email protected] [mailto:[EMAIL PROTECTED] Behalf Of Brian Kotek Sent: Tuesday, 10 July 2007 6:19 AM To: [email protected] Subject: [coldspring-dev] init-method usage I've never heard of this init-method thing. To get ColdSpring to inject your Articles component you just need a setter in your Category component. ColdSpring matches the name of the property to the setter (so property Articles looks for setter setArticles). So make sure in your XML the name of the property matches the name used in the setter. <cffunction name="setArticles" access="public" returntype="void" hint="Articles setter"> <cfargument name="articlesCFC" type="Components.Articles " required="true" /> <cfset Variables.articlesCFC = arguments.articlesCFC /> </cffunction> On 7/9/07, Jonathon Stierman <[EMAIL PROTECTED]> wrote: Anyone have any examples of how this is used? I've got a circular dependency that I'd like to resolve by using this. I got a response from Peter Farrell, in a past thread: >> <bean name="someService" id="dot.path.to.someService" init-method="setup"> >> <property name="someOtherService"><ref bean="someOtherService"/></bean> >> <property name="thatService"><ref bean=""thatService"/></bean> >> </bean> >> >> Order of operations: >> 1. Create someService >> 2. Call init() with any constructor args (must resolve dependencies first) >> 3. Wiring in properties >> 4. Call init-method (yes, it's a misleading name, but it follows the Spring DTD here). In my architecture, we >> call this the setup() method. I figured ColdSpring would just run some magic on my properties and automatically figure out that they should be set in the init-method rather than in the init() constructor, but CS threw an error at me indicating it was still looking for a generic set[myDependency]() method. Here's my config.xml: <!-- File loaded by ColdSpring to perform dependency injection --> <beans> <bean id="Articles" class="Components.Articles" singleton="true"> <constructor-arg name="datasource"><value>${datasource}</value></constructor-arg> </bean> <bean id="Categories" class=" Components.Categories" singleton="true" init-method="setup"> <constructor-arg name="datasource"><value>${datasource}</value></constructor-arg> <property name="articleCFC"><ref bean="Articles" /></property> </bean> </beans> And here's my Categories.cfc: <cfcomponent hint="Add/Edit/Delete Categories"> <cfset Variables.datasource = "" /> <cfset Variables.articlesCFC = "" /> <cffunction name="init" access="public" returntype="Components.Categories" hint="I initialize myself"> <cfargument name="datasource" type="string" required="false" /> <cfset Variables.datasource = arguments.datasource /> <cfreturn this /> </cffunction> <cffunction name="setup" access="public" returntype="Components.Categories" hint="I post-initilize myself for circular dependencies"> <cfargument name="articlesCFC" type="Components.Articles" required="false" /> <cfset Variables.articlesCFC = arguments.articlesCFC /> <cfreturn this /> </cffunction> </cfcomponent> What's the syntax for making the init-method concept work? I googled around a bit, but kept getting matches regarding the regular init() constructor rather than the init-method usage. Jonathon
