jamesarosen/ember-cpm — pull request #17 by jamesarosen (2014-03-04 23:44:20+00:00)
Title: Add "service" macro

This macro lets object look up services from the container. It offers an alternative to `needs` and `Ember.Container.prototype.injection`.

The weakness of `needs` is that it is somewhat cumbersome. Declaring

needs: [ "posts" ]

will add support for `this.get('controllers.posts')`. A standard practice is to alias that to `posts`, but that essentially means declaring the dependency twice.

The weakness of `Ember.Container.prototype.injection` is that it has to be done centrally. That's great for very generic things like injecting the current user into *all* controllers. It's not so nice when you need to connect just a couple out of your dozens or hundreds of controllers.

It would be easy to add a "fromContainer" macro to allow objects to look up arbitrary dependencies from the container. That, however, leads to spaghetti code. The intent of this macro is limited to making it easy to look up central services from wherever they are needed.