1

I use ember-data and I need to insert dependency into data adapter of store. Here is simplified code:

window.App = Ember.Application.create({
  ready: function() {
    this.register('database:current', this.Database);

     // this works fine, this.get('database') inside routes works ok
    this.inject('route', 'database', 'database:current');

    // but this does not work
    this.inject(App.SqliteAdapter, 'database', 'database:current');

    // also tried this:
    // this.inject('dataAdapter', 'database', 'database:current');
  }
});

App.Store = DS.Store.extend({
  revision: 13,
  adapter: App.SqliteAdapter
});

App.SqliteAdapter = DS.Adapter.extend({
  find: function(store, type, id) {
    var db = this.get('database');
    console.log(db); // this is undefined
  }
});

App.Database = Ember.Object.extend({});

Why doesn't this code work?

Versions:

DEBUG: Ember      : 1.1.2
DEBUG: Ember Data : 1.0.0-beta.3
DEBUG: Handlebars : 1.0.0
DEBUG: jQuery     : 2.0.3 
4

1 回答 1

0

您可以像这样注入适配器:

this.inject('adapter', 'database', 'database:current');

您可以在我对ember register injection singleton的回答中看到更多注入示例。

于 2013-11-08T09:14:29.870 回答