Difference between revisions of "App Bean Config"

From ADF Docs
Jump to: navigation, search
(Architecture)
(Example)
 
(23 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
== Overview ==
 
== Overview ==
The App Bean Config is the custom application configuration file for the lightwire object factory. This file establishes the bean configuration with application-specific components and ADF library components.
+
Each [[ADF Applications|ADF Application]] must contain an App Bean Config (appBeanConfig.cfm) in the root of the Applications folder (e.g. /ADF/apps/myApp/appBeanConfig.cfm).
  
The App Bean Config must have the file name 'AppBeanConfig.cfm' and be located at the root of the custom application directory.
+
The App Bean Config is the ADF Application's configuration file for the LightWire object factory. This file establishes the bean (components) that you want to use within your application.  The App Bean Config will contain application-specific components in addition to ADF library components.
  
 
== Architecture ==
 
== Architecture ==
The App Bean Config is separated into 6 sections:   
+
The App Bean Config is separated into three sections:   
* Initialization: set up variables to be used in this configuration file.
 
  // App specific variables
 
  appBeanName = "STARTER_APP";
 
  // Get the com path for the current custom application
 
  appComPath = getComPathForCustomAppDir(GetCurrentTemplatePath());
 
* Load the custom application App component.  This component extends the Core Application Base component (\ADF\Core\AppBase.cfc) in the ADF [[Core]], creating the custom application singleton where the dependencies will be injected.
 
  // Load the APP Base
 
  addSingleton("#appComPath#App", appBeanName);
 
* Load the custom application components.  Create singletons, transients, and dependencies for the specific components within the custom application.
 
  // Load the STARTER APP service component
 
  /*
 
    addSingleton("#appComPath#MYCOMPONENT", "MYCOMPONENT");
 
    addConstructorDependency(appBeanName, "MYCOMPONENT");
 
  */
 
* Load the ADF library components.  Create the dependencies to the custom application singleton. 
 
  // Dependecies from ADF Lib
 
  addConstructorDependency(appBeanName, "cedata_1_0", "cedata");
 
  addConstructorDependency(appBeanName, "scripts_1_0", "scripts");
 
* Call the ADFOverrides function.  This function overrides ADF library components at the custom application level.
 
  // Load the Custom App overrides
 
  ADFOverrides(appComPath, appBeanName);
 
* Call the loadAppSiteComponents function.  This function loads the site level application components into the object factory, giving objects a unique name with the ''AppBeanName_SiteID_ComponentName''.
 
  //Load the site level application components
 
  loadAppSiteComponents(appBeanName);
 
  
== App Component (App.cfc) ==
+
=== Initialization ===
All custom applications must contain the App component (App.cfc).
+
* Set up variables to be used in this configuration file.
 +
* Load the ADF application App component.  This establishes the bean for the application by creating the singleton object where the dependencies will be injected.  
 +
<source lang="java">
 +
// App specific variables
 +
appBeanName = "STARTER_APP";
 +
// Get the com path for the current custom application
 +
appComPath = getComPathForCustomAppDir(GetCurrentTemplatePath());
 +
// Load the APP Base
 +
addSingleton("#appComPath#App", appBeanName);
 +
</source>
  
This is a simple component that is used as the base object for the custom application where all the dependencies will be injected.  This component extends the AppBase component in the ADF [[Core|Core]].
+
=== Inject Components ===
 +
* Inject the ADF application components in the applications bean object.  Create singletons, transients, and dependencies for the specific components.
 +
<source lang="java">
 +
// Load the STARTER APP service component
 +
addSingleton("#appComPath#myComponent", "myComponent");
 +
addConstructorDependency(myComponent, "myComponent");
 +
addTransient("#appComPath#myOtherComponent", "myOtherComponent");
 +
</source>
 +
 
 +
=== Inject ADF Library ===
 +
* Inject the ADF library components into the applications bean object.
 +
<source lang="java">
 +
// Dependecies from ADF Lib
 +
addConstructorDependency(appBeanName, "cedata_1_0", "cedata");
 +
addConstructorDependency(appBeanName, "scripts_1_0", "scripts");
 +
</source>
 +
 
 +
== Example ==
 +
Lets say you are building a new Twitter application.  Your application may contain the following code:
 +
* /ADF
 +
** /apps - contains all installed [[ADF Application]](s)
 +
*** /twitty - your applications directory
 +
**** /components - contains all of the components for your application
 +
***** App.cfc - core CFC for your application
 +
***** twittyService.cfc - service based CFC component
 +
***** twittyDAO.cfc - data access object
 +
**** /customcf - custom script code for your application
 +
**** /customfields - custom fields for your application
 +
**** /datasheet-modules - datasheet modules for your application
 +
**** /renderhandlers - any renderhandlers for your application
 +
**** appBeanConfig.cfm - configuration of your applications components
 +
 
 +
A sample appBeanConfig.cfm would look like this:
 +
 
 +
<source line="GESHI_FANCY_LINE_NUMBERS" lang="cfm">
 +
<cfscript>
 +
// App specific variables
 +
appBeanName = "twitty";
 +
// Get the com path for the current custom application
 +
appComPath = getComPathForCustomAppDir(GetCurrentTemplatePath());
 +
 +
// Load the APP Base
 +
addSingleton("#appComPath#App", appBeanName);
 +
 +
// Load the Application level components
 +
addSingleton("#appComPath#twittyService", "twittyService");
 +
addConstructorDependency(appBeanName, "twittyService");
 +
addSingleton("#appComPath#twittyDAO", "twittyDAO");
 +
addConstructorDependency(appBeanName, "twittyDAO");
 +
 +
// Dependecies from ADF Lib
 +
addConstructorDependency(appBeanName, "scripts_1_0", "scripts");
 +
addConstructorDependency(appBeanName, "ceData_1_0", "ceData");
 +
addConstructorDependency(appBeanName, "csContent_1_0", "csContent");
 +
</cfscript>
 +
</source>
 +
 
 +
* On line 3 we give the App a name.  This must be a unique name that must not be in use ([[Determining ADF Application Name]]).
 +
* On line 8 we load the Applications' [[ADF Application Core Component|App.cfc]] into the [[Glossary|Object Factory]] using the name provided (e.g. "twitty")
 +
Note: the "addSingleton()" method call essentially tells the Object Factory about this component
 +
* On lines 11-14 we are adding the Site level components.  This is a two step process 1) Register the component with the Object Factory (addSinglton) and 2) Inject the component into the application (more on the value of injecting components later in this page)
 +
* Finally, on lines 17-19 we inject some ADF Library Components into the application (specifying which versions we want to use)
 +
 
 +
=== Injection and Singltons ===
 +
The core component of your application ([[Application Core Component|ADF.cfc]]) is made available to you in your code as "application.appname" (or application.twitty in the case of the example).
 +
 
 +
Additionally, the components you load into the application (Inject) are available as "application.appname.component" (or application.twitty.twittyDAO for example).
 +
 
 +
=== Sample coding ===
 +
Essentially, what the appBeanConfig.cfm allows you to do is to easily call your application and specific versions of the ADF Libarary components within your application code.  So for instance, if your twittyDAO.cfc contained a function called "addTweet" you could easily write code like this within your appliacation:
 +
 
 +
<source lang="cfm">
 +
<cfscript>
 +
  application.twitty.twittyDAO.addTweet("The CommonSpot ADF is wicked awesome");
 +
</cfscript>
 +
</source>
 +
 
 +
== Related Guides ==
 +
* [[ADF Application Core Component]]
 +
* [[ADF Applications]]
 +
* [[Building an ADF Application]]

Latest revision as of 16:19, 21 April 2010

Overview

Each ADF Application must contain an App Bean Config (appBeanConfig.cfm) in the root of the Applications folder (e.g. /ADF/apps/myApp/appBeanConfig.cfm).

The App Bean Config is the ADF Application's configuration file for the LightWire object factory. This file establishes the bean (components) that you want to use within your application. The App Bean Config will contain application-specific components in addition to ADF library components.

Architecture

The App Bean Config is separated into three sections:

Initialization

  • Set up variables to be used in this configuration file.
  • Load the ADF application App component. This establishes the bean for the application by creating the singleton object where the dependencies will be injected.
// App specific variables
appBeanName = "STARTER_APP";
// Get the com path for the current custom application
appComPath = getComPathForCustomAppDir(GetCurrentTemplatePath());
// Load the APP Base
addSingleton("#appComPath#App", appBeanName);

Inject Components

  • Inject the ADF application components in the applications bean object. Create singletons, transients, and dependencies for the specific components.
 
// Load the STARTER APP service component
addSingleton("#appComPath#myComponent", "myComponent");
addConstructorDependency(myComponent, "myComponent");
addTransient("#appComPath#myOtherComponent", "myOtherComponent");

Inject ADF Library

  • Inject the ADF library components into the applications bean object.
// Dependecies from ADF Lib
addConstructorDependency(appBeanName, "cedata_1_0", "cedata");
addConstructorDependency(appBeanName, "scripts_1_0", "scripts");

Example

Lets say you are building a new Twitter application. Your application may contain the following code:

  • /ADF
    • /apps - contains all installed ADF Application(s)
      • /twitty - your applications directory
        • /components - contains all of the components for your application
          • App.cfc - core CFC for your application
          • twittyService.cfc - service based CFC component
          • twittyDAO.cfc - data access object
        • /customcf - custom script code for your application
        • /customfields - custom fields for your application
        • /datasheet-modules - datasheet modules for your application
        • /renderhandlers - any renderhandlers for your application
        • appBeanConfig.cfm - configuration of your applications components

A sample appBeanConfig.cfm would look like this:

<cfscript>
 // App specific variables
 appBeanName = "twitty";
 // Get the com path for the current custom application
 appComPath = getComPathForCustomAppDir(GetCurrentTemplatePath());
	
 // Load the APP Base
 addSingleton("#appComPath#App", appBeanName);
	
 // Load the Application level components
 addSingleton("#appComPath#twittyService", "twittyService");
 addConstructorDependency(appBeanName, "twittyService");
 addSingleton("#appComPath#twittyDAO", "twittyDAO");
 addConstructorDependency(appBeanName, "twittyDAO");
	
 // Dependecies from ADF Lib
 addConstructorDependency(appBeanName, "scripts_1_0", "scripts");
 addConstructorDependency(appBeanName, "ceData_1_0", "ceData");
 addConstructorDependency(appBeanName, "csContent_1_0", "csContent");
</cfscript>
Note: the "addSingleton()" method call essentially tells the Object Factory about this component
  • On lines 11-14 we are adding the Site level components. This is a two step process 1) Register the component with the Object Factory (addSinglton) and 2) Inject the component into the application (more on the value of injecting components later in this page)
  • Finally, on lines 17-19 we inject some ADF Library Components into the application (specifying which versions we want to use)

Injection and Singltons

The core component of your application (ADF.cfc) is made available to you in your code as "application.appname" (or application.twitty in the case of the example).

Additionally, the components you load into the application (Inject) are available as "application.appname.component" (or application.twitty.twittyDAO for example).

Sample coding

Essentially, what the appBeanConfig.cfm allows you to do is to easily call your application and specific versions of the ADF Libarary components within your application code. So for instance, if your twittyDAO.cfc contained a function called "addTweet" you could easily write code like this within your appliacation:

<cfscript>
  application.twitty.twittyDAO.addTweet("The CommonSpot ADF is wicked awesome");
</cfscript>

Related Guides