diff options
| author | Igor Minar | 2012-01-15 23:28:10 -0800 |
|---|---|---|
| committer | Igor Minar | 2012-01-17 09:49:37 -0800 |
| commit | 92af30ce6e99676c71c85bd08962b68629564908 (patch) | |
| tree | 4adf4b56cbf7c9fb6ee9dee8f40dd16fb2199842 /docs/content/guide/dev_guide.services.registering_services.ngdoc | |
| parent | 54581d36df74ac128a078aafb3e4b66e0b1599f3 (diff) | |
| download | angular.js-92af30ce6e99676c71c85bd08962b68629564908.tar.bz2 | |
docs(*): various doc fixes
Diffstat (limited to 'docs/content/guide/dev_guide.services.registering_services.ngdoc')
| -rw-r--r-- | docs/content/guide/dev_guide.services.registering_services.ngdoc | 64 |
1 files changed, 0 insertions, 64 deletions
diff --git a/docs/content/guide/dev_guide.services.registering_services.ngdoc b/docs/content/guide/dev_guide.services.registering_services.ngdoc deleted file mode 100644 index 25a51504..00000000 --- a/docs/content/guide/dev_guide.services.registering_services.ngdoc +++ /dev/null @@ -1,64 +0,0 @@ -@ngdoc overview -@name Developer Guide: Angular Services: Registering Angular Services -@description - -To register a service, retrieve the {@link api/angular.module.AUTO.$provide $provide} service and use one of itse -registration methods for new service declaration. The following pseudo-code shows a simple service registration: - -<pre> -$provide.factory('service id', function() { - var shinyNewServiceInstance; - //factory function body that constructs shinyNewServiceInstance - return shinyNewServiceInstance; -}); -</pre> - -Note that you are not registering a service instance, but rather a factory function that will -create this instance when called. - -# Instantiating Angular Services - -A service can be instantiated eagerly or lazily. By default angular instantiates services lazily, -which means that a service will be created only when it is needed for instantiation of a service or -an application component that depends on it. In other words, angular won't instantiate lazy -services unless they are requested directly or indirectly by the application. - -Eager services on the other hand, are instantiated right after the injector itself is created, -which happens when the angular {@link dev_guide.bootstrap application initializes}. - -To override the default, you can request that a service is eagerly instantiated as follows: - -<pre> -angular.module.ng('service id', function() { - var shinyNewServiceInstance; - //factory function body that constructs shinyNewServiceInstance - return shinyNewServiceInstance; -}); -</pre> - -* Nothing in your application declares this service as its dependency, and this service affects the -state or configuration of the application (e.g. a service that configures `$route` or `$resource` -services) -* A guarantee is needed that the service will be instantiated at application boot time, usually -because the service passively observes the application and it is optional for other application -components to depend on it. An example of this scenario is a service that monitors and logs -application memory usage. - -Lastly, it is important to realize that all angular services are applicaiton singletons. This means -that there is only one instance of a given service per injector. Since angular is lethally allergic -to the global state, it is possible to create multiple injectors, each with its own instance of a -given service, but that is rarely needed, except in tests where this property is crucially -important. - - -## Related Topics - -* {@link dev_guide.services.understanding_services Understanding Angular Services} -* {@link dev_guide.services.creating_services Creating Angular Services} -* {@link dev_guide.services.managing_dependencies Managing Service Dependencies} -* {@link dev_guide.services.injecting_controllers Injecting Services Into Controllers } -* {@link dev_guide.services.testing_services Testing Angular Services} - -## Related API - -* {@link api/angular.module.ng Angular Service API} |
