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?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Michal Charemza
  • 25,940
  • 14
  • 98
  • 165
  • The injection into controllers and routes works? – mavilein Mar 14 '13 at 09:15
  • Yes, it seems to. The pusher object is available in the activate method of a router by this.get('pusher'). If I comment out the line about injecting into the router, then the result of that call is undefined. – Michal Charemza Mar 14 '13 at 09:27
  • 1
    First and foremost: I don't think that you can make the 'pusher' available in the init method of your adapter. I think Ember will instantiate the adapter (=the init method is run) and afterwards it would inject those dependencies. – mavilein Mar 14 '13 at 10:22

0 Answers0