You can use the model="" named attribute on your lightning component, or app. See below:
First line of my lightning application:
<aura:application model="ConfigurationModel" controller="ConfigurationController">
Here's my ConfigurationModel Apex class:
/**
* @author Charles Naccio
* @date 10/14/2015
*
* @group Configuration
* @group-content ../../ApexDocContent/Configuration.htm
*
* @description Configuration model class which is used by the Configuration lightning application. This class
* provides the data needed for the lightning application's initial state.
*/
public with sharing class ConfigurationModel extends lightning_Response implements lightning_IResponse {
/*******************************************************************************************************
* @description List of supported gateways that can be configured.
*/
@AuraEnabled
public List<String> supportedGateways {get;set;}
/*******************************************************************************************************
* @description Primary configured gateway. Although configuration is setup to support multiple gateways
* we currently only support a single configured gateway.
*/
@AuraEnabled
public Gateway gateway {get;set;}
/*******************************************************************************************************
* @description Nested class to model gateway configuration in a lightning friendly way
*/
private class Gateway {
/*******************************************************************************************************
* @description Gateway name
*/
private String name {get;set;}
/*******************************************************************************************************
* @description Gateway login. This can either be an actual login to be used with password below,
* or an API key; whichever is needed for authentication.
*/
private String login {get;set;}
/*******************************************************************************************************
* @description Gateway password if applicable
*/
private String password {get;set;}
/*******************************************************************************************************
* @description Gateway application id; not used by all gateways
*/
private String applicationId {get;set;}
/*******************************************************************************************************
* @description If gateway is in test mode; defaults to false.
*/
private Boolean testMode {get;set;}
/*******************************************************************************************************
* @description Configuration tab index controls where this configuration element is displayed in the UI
*/
private Double tabIndex {get;set;}
/*******************************************************************************************************
* @description Create new instance of gateway configuration
* @example
* ConfigurationModel.Gateway gateway = new ConfigurationModel.Gateway();
*/
private Gateway(Configuration configuration) {
configuration_Merchant_Gateway gatewayConfiguration = configuration.merchant.gateways.primary;
this.name = gatewayConfiguration.name;
this.login = gatewayConfiguration.login;
this.password = gatewayConfiguration.password;
this.applicationId = gatewayConfiguration.applicationId;
this.testMode = gatewayConfiguration.testMode;
this.tabIndex = gatewayConfiguration.tabIndex;
}
/*******************************************************************************************************
* @description Get configured gateway name
* @return Configured gateway name
* @example
* String gatewayName = gateway.getName();
*/
@AuraEnabled
public String getName() {
return this.name;
}
/*******************************************************************************************************
* @description Get configured gateway Login
* @return Configured gateway login
* @example
* String gatewayLogin = gateway.getLogin();
*/
@AuraEnabled
public String getLogin() {
return this.login;
}
/*******************************************************************************************************
* @description Get configured gateway password
* @return Configured gateway password
* @example
* String gatewayPassword = gateway.getPassword();
*/
@AuraEnabled
public String getPassword() {
return this.password;
}
/*******************************************************************************************************
* @description Get configured gateway applicationId
* @return Configured gateway applicationId
* @example
* String gatewayApplicationId = gateway.getApplicationId();
*/
@AuraEnabled
public String getApplicationId() {
return this.applicationId;
}
/*******************************************************************************************************
* @description Get configured gateway testMode
* @return Configured gateway testMode
* @example
* Boolean gatewayTestMode = gateway.getTestMode();
*/
@AuraEnabled
public Boolean getTestMode() {
return this.testMode;
}
/*******************************************************************************************************
* @description Get configured gateway tabIndex
* @return Configured gateway tabIndex
* @example
* Double gatewayTabIndex = gateway.getTabIndex();
*/
@AuraEnabled
public Double getTabIndex() {
return this.tabIndex;
}
}
/*******************************************************************************************************
* @description Create new instance of Configuration Model
* @example
* ConfigurationModel configurationModel = new ConfigurationModel();
*/
public ConfigurationModel() {
try {
Configuration configuration = new Configuration();
this.supportedGateways = configuration.merchant.gateways.supported;
this.gateway = new Gateway(configuration);
} catch(Exception e) {
// Setup error
this.error = new lightning_Response_Error(e);
}
}
/*******************************************************************************************************
* @description Return lightning response error
* @example
* lightning_Response_Error = new ConfigurationModel.getError();
*/
@AuraEnabled
public lightning_Response_Error getError() {
return this.error;
}
}