Looking to inject dependencies into my Ember models.
https://github.com/emberjs/ember.js/issues/3670 mentions that this feature is disabled. To enable MODEL_FACTORY_INJECTIONS
, there is a guide at https://github.com/stefanpenner/ember-cli/blob/master/blueprint/app/app.js#L4. This should allow injecting dependencies into models, although I am facing difficulties in implementing it.
If the above solution doesn't work, are there alternative methods to inject a reference to a global singleton object app-wide into an Ember.Model without just adding it to the app's namespace (e.g. App.ImAGlobalconfig`)?
Here is the initializer code snippet where I'm trying to implement this:
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'); // Still facing issues with this!
App.advanceReadiness();
}
).fail(
function(status, request, error) {
console.log('Unable to load config with: ' + error);
}
);
}
});
Any help or opinions on this matter would be greatly appreciated. Thank you.