Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 838
typeoneerror Avatar asked Nov 09 '22 23:11

typeoneerror


1 Answers

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});
    }
};
like image 87
Alex Avatar answered Nov 14 '22 21:11

Alex