Changes between Initial Version and Version 1 of DeveloperGuidelines/EdenMobile/Services


Ignore:
Timestamp:
08/10/17 13:49:43 (8 years ago)
Author:
Dominic König
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DeveloperGuidelines/EdenMobile/Services

    v1 v1  
     1= EdenMobile Services =
     2[[TOC]]
     3
     4Services in EdenMobile are singleton objects providing access to global data and functionality.
     5
     6== Services Overview ==
     7
     8||='''Name'''=||='''Functionality'''=||
     9||emDB||Low-level Database Access (tables)||
     10||emDialogs||Generic !Popup/Popover User Dialogs||
     11||emConfig||Global Configuration Settings||
     12||emFiles||Uploaded Files||
     13||emForms||Introspective Form Building||
     14||emResources||High-level Database Access (resources)||
     15||emS3JSON||S3JSON codec||
     16||emServer||Sahana Server Access||
     17||emSQL||SQL Construction (SQLite)||
     18||emSync||Synchronization with Sahana Server||
     19||emUtils||Utility Functions||
     20
     21== Accessing Services ==
     22
     23To access a service in a controller/service/directive/filter, it must be '''injected'''.
     24
     25To do this, the service can be added to the '''dependency list''' in the declaration:
     26
     27{{{#!js
     28EdenMobile.controller('EMSomeController', [
     29    '$scope', '$state', '$stateParams', 'emDialogs',    // <== depenency list
     30    function($scope, $state, $stateParams, emDialogs) { // <== injected dependencies become parameters
     31
     32    // Accessing the service:
     33    emDialogs.confirmation(...);
     34
     35});
     36}}}
     37
     38...or it can be '''dynamically injected''' (e.g. to avoid circular dependencies), using the {{{$injector}}} service:
     39
     40{{{#!js
     41EdenMobile.factory('emSomeService', [
     42    '$injector',            // <== $injector in dependency list
     43    function ($injector) {  // <== $injector as parameter
     44
     45    // Dynamically inject, then access the service
     46    var emDialogs = $injector.get('emDialogs');
     47    emDialogs.confirmation(...);
     48
     49});
     50}}}