aboutsummaryrefslogtreecommitdiffstats
path: root/src/Injector.js
diff options
context:
space:
mode:
authorVojta Jina2012-03-08 16:53:15 -0800
committerVojta Jina2012-03-09 10:10:29 -0800
commit0bfaa579c04d1b7cd21fbe16bfbc47a684f223b3 (patch)
tree1e6c2147eed623ea9d17570511df1586a0af8449 /src/Injector.js
parent00d4427388eeec81d434f9ee96bb7ccc70190923 (diff)
downloadangular.js-0bfaa579c04d1b7cd21fbe16bfbc47a684f223b3.tar.bz2
feat($provide.service): Add $provide.service() for registering a class
Diffstat (limited to 'src/Injector.js')
-rw-r--r--src/Injector.js25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/Injector.js b/src/Injector.js
index dc37a97c..10072959 100644
--- a/src/Injector.js
+++ b/src/Injector.js
@@ -230,7 +230,7 @@ function inferInjectionArgs(fn) {
*
* A short hand for configuring services if only `$get` method is required.
*
- * @param {string} name The name of the instance. NOTE: the provider will be available under `name + 'Provider'` key.
+ * @param {string} name The name of the instance.
* @param {function()} $getFn The $getFn for the instance creation. Internally this is a short hand for
* `$provide.provider(name, {$get: $getFn})`.
* @returns {Object} registered provider instance
@@ -239,13 +239,27 @@ function inferInjectionArgs(fn) {
/**
* @ngdoc method
+ * @name angular.module.AUTO.$provide#service
+ * @methodOf angular.module.AUTO.$provide
+ * @description
+ *
+ * A short hand for registering service of given class.
+ *
+ * @param {string} name The name of the instance.
+ * @param {Function} constructor A class (constructor function) that will be instantiated.
+ * @returns {Object} registered provider instance
+ */
+
+
+/**
+ * @ngdoc method
* @name angular.module.AUTO.$provide#value
* @methodOf angular.module.AUTO.$provide
* @description
*
* A short hand for configuring services if the `$get` method is a constant.
*
- * @param {string} name The name of the instance. NOTE: the provider will be available under `name + 'Provider'` key.
+ * @param {string} name The name of the instance.
* @param {*} value The value.
* @returns {Object} registered provider instance
*/
@@ -296,6 +310,7 @@ function createInjector(modulesToLoad) {
$provide: {
provider: supportObject(provider),
factory: supportObject(factory),
+ service: supportObject(service),
value: supportObject(value),
constant: supportObject(constant),
decorator: decorator
@@ -342,6 +357,12 @@ function createInjector(modulesToLoad) {
function factory(name, factoryFn) { return provider(name, { $get: factoryFn }); }
+ function service(name, constructor) {
+ return factory(name, ['$injector', function($injector) {
+ return $injector.instantiate(constructor);
+ }]);
+ }
+
function value(name, value) { return factory(name, valueFn(value)); }
function constant(name, value) {