Reputation: 2650
When I try to instantiate one CFC from 2 different CFCs, ColdFusion returns a 500 error. I tried making one of the CFC extend the other, but it did not solve the issue. Is this possible, or am I simply doing something incorrectly?
<!--- one.cfc --->
<cfcomponent name="FirstCFC">
<cfset this.Tools = createObject('component', 'toolbox').init()>
....
</cfcomponent>
<!--- two.cfc --->
<cfcomponent name="SecondFC">
<cfset this.Tools = createObject('component', 'toolbox').init()>
....
</cfcomponent>
<!--- toolbox.cfc --->
<cfcomponent name="Toolbox">
<cffunction name="init" access="public">
<cfreturn this>
</cffunction>
<cffunction name="someFunc" access="public">
</cffunction>
</cfcomponent>
Here is a screenshot of the 500 error
Here is a more "full" code sample
Upvotes: 1
Views: 228
Reputation: 10857
Shawn is right. He posted more code and you can see two.cfc makes tools.cfc and tools.cfc makes two.cfc.
You need to move to an injection style setup (ala ColdSpring for example).
Upvotes: 1
Reputation: 3762
The java stack trace you've included is indicitive of an infinite recursion error. Take care when creating objects of type A, which have a new object of type B in their pseudo-constructor. If the object B itself creates an object of type A in its pseudo-constructor, you have yourself an infinite recursion of objects being created, ending in an ugly java stack trace.
Upvotes: 3