Hi guys,
I tried to update to latest Ember, everything went great except one issue with initializers. To this time I used this initializer to inject logged in user to all controllers, views and models:
App.initializer({
name: 'currentUser',
initialize: function(container, application) {
var store = container.lookup('store:application'),
session = $.cookie('session');
if(!Ember.isEmpty(session)) {
application.deferReadiness();
session = session.split(':');
$.ajaxSetup({
headers: {
'Authorization': session[1]
}
});
store.find('user', session[0]).then(function(user) {
user.get('profile').then(function() {
application.register('user:current', user, {
instantiate: false,
singleton: true
});
application.inject('controller', 'currentUser', 'user:current');
application.inject('view', 'currentUser', 'user:current');
application.inject('model', 'currentUser', 'user:current');
application.advanceReadiness();
}, function() {
App.deauthenticate();
application.advanceReadiness();
});
}, function() {
App.deauthenticate();
application.advanceReadiness();
});
}
}
});
However now it throws deprecation:
DEPRECATION: `lookup` was called on a Registry. The `initializer` API no longer receives a container, and you should use an `instanceInitializer` to look up objects from the container. See http://emberjs.com/guides/deprecations#toc_deprecate-access-to-instances-in-initializers for more details.
at Object.Registry.lookup (http://localhost:9000/bower_components/ember/ember.debug.js:1619:26)
at Object.App.initializer.initialize [as initialize] (http://localhost:9000/scripts/combined-scripts.js:117:31)
at http://localhost:9000/bower_components/ember/ember.debug.js:4103:23
at http://localhost:9000/bower_components/ember/ember.debug.js:4126:9
at visit (http://localhost:9000/bower_components/ember/ember.debug.js:2147:7)
at DAG.topsort (http://localhost:9000/bower_components/ember/ember.debug.js:2259:11)
at Namespace.default.extend._runInitializer (http://localhost:9000/bower_components/ember/ember.debug.js:4125:13)
at Namespace.default.extend.runInitializers (http://localhost:9000/bower_components/ember/ember.debug.js:4099:12)
at Namespace.default.extend.boot (http://localhost:9000/bower_components/ember/ember.debug.js:4017:12)
I unsuccessfully tried to refactor this initializer, then searched the web for solution, found discussion on GitHub that lead to conclusion that logic like that may be moved to beforeModel of application route. However it’s not applicable in this case because I definitely need currentUser to be injected everywhere before the application load. Is there any way to workaround this issue, maybe some way of accessing store without raising a deprecation warning?