Ember by default injects dependencies when loading your application, using mostly conventions, for example, if you use ember data, then an instance of the store class is introduced in each route and controller in your application, so you can get the link later by simply doing this.get('store') inside any route or controller.
For example, here is a piece of code in which store registered by default (taken from source )
Ember.onLoad('Ember.Application', function(Application) { Application.initializer({ name: "store", initialize: function(container, application) { application.register('store:main', application.Store); ... } container.lookup('store:main'); } });
And then introduced ( source )
Application.initializer({ name: "injectStore", initialize: function(container, application) { application.inject('controller', 'store', 'store:main'); application.inject('route', 'store', 'store:main'); application.inject('dataAdapter', 'store', 'store:main'); } ... });
In other words, register and inject are methods for registering dependencies and entering them yourself.
Suppose you have a Session object that you populate after starting a server request when you start the application and with which you want to have a link on each controller, you can do something like this:
var App = Ember.Application.create({ ready: function(){ this.register('session:current', App.Session, {singleton: true}); this.inject('controller', 'session', 'session:current'); } }); App.Session = Ember.Object.extend({ sessionHash: '' });
This code would set the Session property of each controller instance to one instance of App.Session , so you could make this.get('session') in any controller and get a reference to it, and since it is defined as a singleton it will always be the same Session object .
With register you can register controllers, models, views, or any arbitrary type of object. inject , on the other hand, can inject all instances of a given class. For example, inject('model', 'session', 'session:current') also introduces the Session property by an instance of session:current in all models. To introduce a Session object, say, on an IndexView you could inject('view:index', 'session', 'session:current') .
Although register and inject are very powerful, you should use them wisely and only if you really know that there is no other way to achieve your goal, I think the lack of documentation is an indicator of discouragement.
Update - no good explanation without a working example
Since you basically need to provide a working example with an explanation, it goes there: http://jsbin.com/usaluc/6/edit . Please note that in this example we can simply access the specified sessionHash by accessing the current object of the controller session with {{controller.session.sessionHash}} in each route we are in, this is the merit of what we did by registering and by entering the App.Session object in each application controller.
Hope this helps.