Singleton dependency injection in ember-cli

Just converted my application to ember-cli, but I no longer know how to use Ember.Application.register , because register seems unavailable when the application is started with extend , not create .

 import Ember from 'ember'; import App from 'myapp/app'; var AdminMyController = Ember.ObjectController.extend({ }); // THROWS ERROR HERE BECAUSE register isn't, uh...registered? App.register('controller:adminMyController', AdminMyController, { singleton: false }); export default AdminMyController; 

Previously, since the application was global, I could register this right in the same class.

Do I have to move all registrar calls to the initializer so that I can access the application instance?

+5
source share
1 answer

I believe that the initializer will do this for you. You need to create the initializers folder in the application directory (at the same level as controllers, templates, etc.). This file should go there.

 import Ember from 'ember'; var AdminMyController = Ember.ObjectController.extend({ ... }); export default { name: 'adminMyController', initialize: function (container, application) { container.register('controller:adminMyController', AdminMyController, {singleton: false}); } }; 
+1
source

Source: https://habr.com/ru/post/1206680/


All Articles