Anyone have any examples of how this is used? Ive got a circular
dependency that Id 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. Heres 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 heres 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>
Whats 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