试图更好地了解 ember 的注册和注入。基本上我的代码如下所示:
//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
我只是希望这项服务在整个应用程序中作为单例在全球范围内可用,实现这一目标的最佳方法是什么?重要的是说我设法将我的服务注入模型、视图和控制器,而问题是将它注入我的适配器。
提前致谢