This feature is similar to the Application Settings except that the values stored are instances of objects that are used to provide specific services or additional functionality to the application. Application Services act as Singletons in the sense that the application only uses one instance of each service. Services are stored on the application scope and the framework handles its loading and access.
Any CFC can be loaded as an Application Service as long as it provides a public Init method that take the role of constructor. There are no dependencies between the framework and the CFCs used as Application Services.
To access Application Services within an event handler, use the getService() method passing the assigned service name.
Application Services are declared on the config xml document, under the < services > tag. This tag is a child tag of the document root. Within the services area, each service is declared using the < service > tag. The attributes of this tag are name and class. The first one is used to assign a name by which to refer to the service when using the getService() function. This name can be any string value. The second attribute, class, is used to identify the CFC that implements the service. This can be expressed in dot notation or as a relative path starting from the application root. If the cfc is referred using the relative path, it must include the complete file name.
When instantiating the service, the framework automatically calls the Init() method. To determine the parameters that will be used when calling this method use the < init-param > tag. These tags should be children of the corresponding < service > tag of the service to which they apply. Each < init-param > corresponds to each of the arguments that will be passed to the init method. This tag uses the following attributes:
| Attribute | Description |
| Name | Name of the argument. This name must match the definition on the method signature of the CFC. The framework calls the Init method using named arguments. |
| settingName | [Optional] use this argument to bind the value of the init() argument to the value of a setting defined on the Settings section of the config document. The value of this attribute must match the name of the setting. |
The value of the parameters is defined as the text value of the < init-param > node. However, if the settingName attribute is used on the < init-param > tag, then the setting value overrides the literal value.
Since the controller loads the Application Services during application initialization, forcing an application reset will also force the reload of all services.
