Including Dependencies in the Ember Model

I am trying to inject dependencies into my Ember models.

https://github.com/emberjs/ember.js/issues/3670 , it is said to be disabled. Following a link to https://github.com/stefanpenner/ember-cli/blob/master/blueprint/app/app.js#L4 demonstrates how to enable MODEL_FACTORY_INJECTIONS, which theoretically should allow me to introduce dependencies in my models, however I don’t lucky.

In the absence of this solution, are there other ways to insert a reference to the global singleton application object into the Ember.Model shell, except that it simply removes it into the application namespace (for example, App.ImAGlobalconfig`)?

for reference, this is the initializer I'm working on

App.initializer({
  name: 'preload',
  initialize: function(container/*, application*/) {
    App.deferReadiness();

    Ember.$.ajax({
      url: CONFIG.configURL,
      dataType: 'json',
      context: this
    }).done(
      function(json/*,status, request*/) {
       var appConfig;

        // ...

        container.register('app:config', appConfig, {instantiate: false});
        container.injection('controller', 'appConfig', 'app:config');
        container.injection('route', 'appConfig', 'app:config');
        container.injection('view', 'appConfig', 'app:config');
        container.injection('model', 'appConfig', 'app:config'); // I don't work!

        App.advanceReadiness();
      }
    ).fail(
      function(status, request, error) {
        console.log('Unable to load config with: ' + error);
      }
    );
  }
});

Thanks for any help and opinions.

+2
1

:

Ember.MODEL_FACTORY_INJECTIONS = true;    
App = Ember.Application.create();

App.initializer({
  name: 'model-injection',

  initialize: function(container, application) {

    var cfg = {version: '1'};
    container.register('app:config', cfg, {instantiate: false});


    container.injection('model', 'cfg', 'app:config');
    App.advanceReadiness();
  }
});

App.deferReadiness();

http://emberjs.jsbin.com/lomiy/1/edit

+2

All Articles