Ember.js 余烬寄存器注入单例

Ember.js 余烬寄存器注入单例,ember.js,singleton,Ember.js,Singleton,试图更好地了解余烬的注册和注入。 基本上,我的代码如下所示: //creating a service Nerdeez.Wormhole = Ember.Object.extend({ ... }) //registering this service as a singleton App.register('wormhole:current', Nerdeez.Wormhole, {singleton: true}); //wanting to inject this service to

试图更好地了解余烬的注册和注入。 基本上,我的代码如下所示:

//creating a service
Nerdeez.Wormhole = Ember.Object.extend({
...
})

//registering this service as a singleton
App.register('wormhole:current', Nerdeez.Wormhole, {singleton: true});

//wanting to inject this service to be available everywhere in my application
//especially in the adapter where i use it in the ajax hook
App.inject('App', 'wormhole', 'wormhole:current');

//when trying to access this service in the ajax hook in the adapter i get undefined WTF!
App.get('wormhole') === undefined //true
我只是想让这个服务作为一个单体在整个应用程序中全局可用,实现这一点的最佳方法是什么? 重要的是,我设法将我的服务注入到模型、视图和控制器中,问题是将它注入到适配器中


提前感谢

我也找不到将对象注入应用程序的方法,但您可以将其注入适配器(或商店),就像您为路由和控制器对象所做的一样:

// register
App.register('wormhole:current', Nerdeez.Wormhole);

// inject into adapter
App.inject('adapter', 'wormhole', 'wormhole:current');

// inject into store
App.inject('store', 'wormhole', 'wormhole:current');

// inject into routes & controllers
App.inject('route', 'wormhole', 'wormhole:current');
App.inject('controller', 'wormhole', 'wormhole:current');