2

I'm trying to inject a dependency into a data-store adapter, so it's available from its "init" method, onwards, but I'm having trouble. I'm the method outlined in http://livsey.org/blog/2013/02/10/integrating-pusher-with-ember/ to create a "Pusher" object

Ember.Application.initializer({
  name: "pusher",
  initialize: function(container, application) {
    // Original code from blog post
    // use the same instance of Pusher everywhere in the app
    container.optionsForType('pusher', { singleton: true });

    // register 'pusher:main' as our Pusher object
    container.register('pusher', 'main', application.Pusher);

    // inject the Pusher object into all controllers and routes
    container.typeInjection('controller', 'pusher', 'pusher:main');
    container.typeInjection('route', 'pusher', 'pusher:main');

    // My guessed addition
    container.typeInjection('adapter', 'pusher', 'pusher:main');
    container.typeInjection('store', 'pusher', 'pusher:main');
  }
});

But this doesn't seem to work, as in

this.get('pusher');

is undefined in the adapter's init method. Indeed, the adapter's init method method seems to run before the init method of Pusher. How can I get the same object into both the routes and my custom store adapter, without resorting to global variables?

4

0 回答 0