Skip to content

Instantly share code, notes, and snippets.

@christierney402
Last active December 15, 2015 23:28
Show Gist options
  • Save christierney402/5340103 to your computer and use it in GitHub Desktop.
Save christierney402/5340103 to your computer and use it in GitHub Desktop.
CF: Application.cfc Example With DI/1 #snippet
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