First of all, thanks to Sean for taking potshots at the code I displayed :)
Ahem, I mean thanks to Sean and JohnB on their input as to the most efficient
and cleanest way to instantiate CFC's in FB4.1.
Hopefully the original posters are thoroughly confused and don't know what's
what at this point. j/k
So let me start from scratch.
To use CFC's in Fusebox, I always declare the <class>es in the fusebox.xml file.
Then in my controller file I use a "setup" fuseaction to <instantiate> the
CFC's.
Taking Sean's and John's advice I got rid of my prefuseaction in the controller
circuit, and instead use a globalfuseaction to initialize. Here's the updated
code:
---------fusebox.xml.cfm-------------
<!-- class declaration after the circuit declaration -->
<classes>
<class alias="States"
classpath="Ali.GAfb4CFC.com.statesManager"
type="component"
constructor="init" />
<class alias="Customers"
classpath="Ali.GAfb4CFC.com.dmsManager"
type="component"
constructor="init" />
<class alias="VIN"
classpath="Ali.GAfb4CFC.com.vinManager"
type="component"
constructor="init" />
<class alias="Dealer"
classpath="Ali.GAfb4CFC.com.dealerManager"
type="component"
constructor="init" />
<class alias="Rating"
classpath="Ali.GAfb4CFC.com.ratingsManager"
type="component"
constructor="init" />
<class alias="Policy"
classpath="Ali.GAfb4CFC.com.policyManager"
type="component"
constructor="init" />
<class alias="PolicyNumber"
classpath="Ali.GAfb4CFC.com.policyNumberManager"
type="component"
constructor="init" />
<!--<class alias="Car" classpath="Ali.FB41demoApp.Car"
type="component" constructor="init" />
<class alias="SecretAgent"
classpath="Ali.FB41demoApp.SecretAgent" type="component" />
<class alias="Shocker" classpath="Fusebox41.demoApp.DogShocker"
type="java" />-->
</classes>
<!-- set this so we can use JohnB's <lock> -->
<lexicons>
<lexicon namespace="aa" path="aa/"/>
</lexicons>
<!-- after the parameters chunk
in the <preprocess> chunk, the first <fuseaction> is where we call the
Initialize fuseaction which is in the controller circuit
-->
<globalfuseactions>
<preprocess>
<fuseaction action="main.Initialize" />
<fuseaction action="layouts.layContentHeader" />
</preprocess>
<postprocess>
</postprocess>
</globalfuseactions>
<!-- controller/circuit.xml.cfm
Now instead of a prefuseaction, we have 2 regular fuseactions to do the
initialization.
The second fuseaction is private, because it's not called by any other circuit,
it's just an internal fuseaction to be called by Initialization.
We had to break the original code into 2 fuseactions since nesting if's is not
allowed in FB4.1
I use another if in the second fuseaction, on Sean's advice to do the
if-lock-if technique to avoid race conditions I believe, and also to avoid
locking per request.
-->
<fuseaction name="Initialize">
<if condition="NOT
StructKeyExists(application,'appInitialized')">
<true>
<do action="main.setupCFC" />
</true>
</if>
</fuseaction>
<fuseaction name="setupCFC" access="private">
<if condition="NOT
StructKeyExists(application,'appInitialized')">
<true>
<aa.lock mode="start" type="exclusive"
scope="application" />
<instantiate
object="application.statesManager"
class="States"
arguments="request.DSN1"/>
<instantiate
object="application.dmsManager"
class="Customers"
arguments="request.DSN2"/>
<instantiate
object="application.vinManager"
class="VIN"
arguments="request.DSN4"/>
<instantiate
object="application.dealerManager"
class="Dealer"
arguments="request.DSN1"/>
<instantiate
object="application.ratingsManager"
class="Rating"
arguments="request.DSN1"/>
<instantiate
object="application.policyManager"
class="Policy"
arguments="request.bcc,request.DocsFolderGA,request.GAReportingFile,request.GAIDCard,request.GAEvidenceOfIns,request.GASorryFile"/>
<instantiate
object="application.policyNumberManager"
class="PolicyNumber"
arguments="request.DSN1"/>
<set name="application.appInitialized"
value="1"/>
<aa.lock mode="end" />
</true>
</if>
</fuseaction>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Discover CFTicket - The leading ColdFusion Help Desk and Trouble
Ticket application
http://www.houseoffusion.com/banners/view.cfm?bannerid=48
Message: http://www.houseoffusion.com/lists.cfm/link=i:12:6714
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/12
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:12
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.12
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54