Share Services with Dependency Injection

The features we’ve covered so far help you implement a sound design by creating reusable classes and sharing them across objects. Mixins and utilities are great for abstracting behavior, but for more complex abstractions, you’ll want to create a service and use dependency injection to sprinkle it throughout your app.

“Service” can be interpreted to mean different things, so let’s start by defining what we mean by a service. A service is a self-contained unit of functionality. It provides unrelated objects access to its functionality in a loosely coupled way. Ember relies on a few services out of the box. For instance, the application’s instance of Ember.Router is a good example of a service: it manages ...

Get Deliver Audacious Web Apps with Ember 2 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.