Last active
December 15, 2015 23:28
-
-
Save christierney402/5340103 to your computer and use it in GitHub Desktop.
CF: Application.cfc Example With DI/1 #snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
component { | |
this.name = hash( getCurrentTemplatePath() ); | |
// Do not use datasource attribute in cfquery | |
this.datasource = "myDSN"; | |
this.sessionManagement = true; | |
/** | |
* /model/beans/ contains transient CFC's | |
* All others are singleton CFC's | |
* All singletons have their folder singular name appended to the file name. (Example: userService) | |
* Use "application.BF.getBean('userService')" as an example to get a bean | |
* Set properties with accessors in the CFC with the names of the CFC to be injected | |
*/ | |
boolean function onApplicationStart() { | |
// Use only on cfstoredproc datasource attribute | |
application.DSN = this.datasource; | |
// DI/1 Bean Factory | |
application.BF = new model.ioc( "/model" ); | |
return true; | |
} | |
boolean function onRequestStart( required string targetPage ) { | |
if( structKeyExists( URL, 'init' ) and URL.init == 'true' ) { | |
onApplicationStart(); | |
} | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment