Ask Ben: Dynamically Executing ColdFusion Application.cfc Instances

<cfcomponent
	output="false"
	hint="I define application settings for APP 1.">
 
	<!--- Define application settings. --->
	<cfset THIS.Name = "SubAppOne" />
	<cfset THIS.ApplicationTimeout = CreateTimeSpan( 0, 0, 5, 0 ) />
	<cfset THIS.SessionManagement = true />
	<cfset THIS.SessionTimeout = CreateTimeSpan( 0, 0, 5, 0 ) />
 
	<!--- Define request settings. --->
	<cfsetting showdebugoutput="false" />
 
 
	<cffunction
		name="OnSessionStart"
		access="public"
		returntype="void"
		output="false"
		hint="I run when the user's session begins.">
 
		<!---
			Create a new varible to hold the number of times
			that the user has hit this application.
		--->
		<cfset SESSION.HitCount = 0 />
 
		<!--- Return out. --->
		<cfreturn />
	</cffunction>
 
 
	<cffunction
		name="OnRequestStart"
		access="public"
		returntype="boolean"
		output="false"
		hint="I run before the requested template gets processed.">
 
		<!--- Define arguments. --->
		<cfargument
			name="Page"
			type="string"
			required="true"
			hint="I am the requested page."
			/>
 
		<!--- Set up DSN. --->
		<cfset REQUEST.DSN = {
			Source = "app1_dsn",
			Username = "app1_user",
			Password = "monkey"
			} />
 
		<!--- Set up mode. --->
		<cfset REQUEST.Mode = "Dev" />
 
		<!--- Increment session hit count. --->
		<cfset SESSION.HitCount++ />
 
		<!--- Return out. --->
		<cfreturn true />
	</cffunction>
 
 
	<cffunction
		name="OnRequest"
		access="public"
		returntype="void"
		output="true"
		hint="I execute the page template.">
 
		<!--- Define arguments. --->
		<cfargument
			name="Page"
			type="string"
			required="true"
			hint="I am the requested page."
			/>
 
		<!--- Include the requested page. --->
		<cfinclude template="#ARGUMENTS.Page#" />
 
		<!--- Return out. --->
		<cfreturn />
	</cffunction>
 
</cfcomponent>

For Cut-and-Paste