Listing 1: ApplicationMgr.cfc

<cfcomponent displayname="ApplicationMgr">
<!---
App.* Stores Private Application Data
Accesible only within CFC
--->
<cfparam name="App" type="struct" default="#structnew()#">
<cfset App.name = "AbstractApp">
<cfset App.clientManagement = "Yes">
<cfset App.clientStorage = "registry">
<cfset App.setClientCookies = "Yes">
<cfset App.sessionManagement = "No">
<cfset App.sessionTimeout = CreateTimeSpan(0, 2, 0, 0)>
<cfset App.ApplicationTimeout = CreateTimeSpan(0, 2, 0, 0)>
<cfset App.setDomainCookies = "Yes">
<!---
My.* Stores Public Application Data
Accesible via GetValue("VarName")
--->
<cfparam name="My" type="struct" default="#structnew()#">
<cfset My.InstanceID = createUUID()>

<cffunction name="getInstance" access="public"
returntype="struct" output="no">
<cfif NOT IsDefined("Server.ao__ApplicationMgr_AppObj") OR
NOT IsStruct(Server.ao__ApplicationMgr_AppObj)>
<cflock timeout="10" throwontimeout="No"
type="EXCLUSIVE" scope="SERVER">
<cfif NOT IsDefined("Server.ao__ApplicationMgr_AppObj") OR
NOT IsStruct(Server.ao__ApplicationMgr_AppObj)> 
<cfset Server.ao__ApplicationMgr_AppObj = this>
</cfif>
</cflock>
</cfif>
<cfreturn Server.ao__ApplicationMgr_AppObj>
</cffunction>

<cffunction name="Execute" access="public" output="Yes">
<cfapplication
name="#App.name#"
clientManagement="#App.clientManagement#"
clientStorage="#App.clientStorage#"
setClientCookies="#App.setClientCookies#"
sessionManagement="#App.sessionManagement#"
sessionTimeout="#App.sessionTimeout#"
applicationTimeout="#App.applicationTimeout#"
setDomainCookies="#App.setDomainCookies#">
</cffunction>

<!--- GET THE VALUE OF A PROPERTY --->
<cffunction name="getValue" access="public" output="false">
<cfargument name="name" required="Yes" type="string">
<cfif IsDefined("My.#arguments.name#")>
<cfreturn My[arguments.name]>
</cfif>
</cffunction>

</cfcomponent>




Listing 2: BillingAppMgr.cfc

<cfcomponent extends="com.amkor.ApplicationMgr"
displayname="BillingAppMgr">
<!---
App.* Stores Private Application Data
Accesible only within CFC
--->
<cfparam name="App" type="struct" default="#structnew()#">
<cfset App.name = "Billing"><!--- "application_name" --->
<!---
My.* Stores Public Application Data
Accesible via GetValue("VarName")
--->
<cfparam name="My" type="struct" default="#structnew()#">
<cfset My.DSN = "Billing"><!--- datasource name --->
<cfset My.ReportSystem = "Crystal"><!--- Report Server --->
<cffunction name="getInstance" access="public"
returntype="struct" output="no">
<cfif NOT IsDefined("Server.ao__BillingAppMgr_AppObj") OR
NOT IsStruct(Server.ao__BillingAppMgr_AppObj)>
<cflock timeout="10" throwontimeout="No"
type="EXCLUSIVE" scope="SERVER">
<cfif NOT IsDefined("Server.ao__BillingAppMgr_AppObj") OR
NOT IsStruct(Server.ao__BillingAppMgr_AppObj)> 
<cfset Server.ao__BillingAppMgr_AppObj = this>
</cfif>
</cflock>
</cfif>
<cfreturn Server.ao__BillingAppMgr_AppObj>
</cffunction>
</cfcomponent>




Listing 3: QuoteAppMgr.cfc

<cfcomponent extends="com.amkor.ApplicationMgr"
displayname="QuoteAppMgr">
<!---
App.* Stores Private Application Data
Accesible only within CFC
--->
<cfset App.name = "Quote"><!--- "application_name" --->
<!---
My.* Stores Private Application Data
Accesible via GetValue("VarName")
--->
<cfset My.DSN = "Quote"><!--- datasource name --->
<cfset My.ReportSystem = "Actuate"><!--- Report Server --->
<cffunction name="getInstance" access="public"
returntype="struct" output="no">
<cfif NOT IsDefined("Server.ao__QuoteAppMgr_AppObj") OR
NOT IsStruct(Server.ao__QuoteAppMgr_AppObj)>
<cflock timeout="10" throwontimeout="No"
type="EXCLUSIVE" scope="SERVER">
<cfif NOT IsDefined("Server.ao__QuoteAppMgr_AppObj") OR
NOT IsStruct(Server.ao__QuoteAppMgr_AppObj)> 
<cfset Server.ao__QuoteAppMgr_AppObj = this>
</cfif>
</cflock>
</cfif>
<cfreturn Server.ao__QuoteAppMgr_AppObj>
</cffunction>
</cfcomponent>




Listing 4: Application.cfm

<cfset Quote = CreateObject("component",
"com.mycompany.Quote.QuoteAppMgr")>
<cfset Quote = Quote.getInstance()>
<cfset Billing = CreateObject("component",
"com.mycompany.Billing.BillingAppMgr")>
<cfset Billing = Billing.getInstance()>
<cfset Billing.Execute()>




Listing 5: test.cfm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Singleton App Manager Example</title>
</head>
<body><br>Quote System Application<br><br><br>
<cfoutput>DSN:&nbsp;#Quote.getValue("dsn")#</cfoutput>
<br><br><br>
<cfoutput>InstanceID:&nbsp;#Quote.getValue("InstanceID")#</cfoutput>
<br><br><br>
<cfoutput>Report System:&nbsp;#Quote.getValue("ReportSystem")#</cfoutput>
<br><br><br>Billing System<br><br><br><cfoutput>DSN:&nbsp;#Billing.getValue("dsn")#</cfoutput>
<br><br><br>
<cfoutput>Instance ID:&nbsp;#Billing.getValue("InstanceID")#</cfoutput>
<br><br><br>
<cfoutput>Report System:&nbsp;#Quote.getValue("ReportSystem")#</cfoutput>
</body>
</html>