当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - dependency injection without singleton in ember-cli

问题描述:

Just converted my app to ember-cli, but I don't know how to use Ember.Application.register any more because register doesn't seem to be available when Application is started with extend rather than 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, because App was a global, I could register this right in the same class.

Am I going to have to move all the register calls to an initializer so I can get access to the app instance?

网友答案:

I belive an initializer would do this for you. You'll need to create an initializers folder in your app directory (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});
    }
};
分享给朋友:
您可能感兴趣的文章:
随机阅读: