From 1fc3446af5f01008061f0b3da84c72eafc445fec Mon Sep 17 00:00:00 2001 From: Benjamin Fleischer Date: Mon, 30 Mar 2015 15:18:06 -0500 Subject: [PATCH] Document Ember.Service --- ...dependency-injection-and-service-lookup.md | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/source/understanding-ember/dependency-injection-and-service-lookup.md b/source/understanding-ember/dependency-injection-and-service-lookup.md index a7157c982..71c0632c7 100644 --- a/source/understanding-ember/dependency-injection-and-service-lookup.md +++ b/source/understanding-ember/dependency-injection-and-service-lookup.md @@ -227,3 +227,31 @@ Injections can be made onto all of Ember's major framework classes including com --> Dependency injection and service lookup are two powerful tools in your Ember.js toolset, and every mature Ember application will require their use. + +### Dependency Injection with `Ember.Service` + +```JavaScript +import Registry from "container/registry"; +import Service from "ember-runtime/system/service"; +import EmberObject from "ember-runtime/system/object"; +import EmberRoute from "ember-routing/system/route"; +import inject from "ember-runtime/inject"; + +var route = EmberRoute.create(); +var registry = new Registry(); +var container = registry.container(); + +registry.register('route:application', EmberRoute.extend({ + authService: inject.service('auth') +})); + +registry.register('service:auth', Service.extend()); + +var appRoute = container.lookup('route:application'); +var authService = container.lookup('service:auth'); + +appRoute.get('authService') +``` + + +