2

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

このサービスをシングルトンとしてアプリケーション全体でグローバルに利用できるようにしたいのですが、これを実現する最善の方法は何ですか? サービスをモデル、ビュー、およびコントローラーに注入することに成功し、問題はそれをアダプターに注入することであると言うことが重要です。

前もって感謝します

4

1 に答える 1

0

オブジェクトをアプリに挿入する方法もわかりませんでしたが、ルートとコントローラー オブジェクトの場合と同じように、アダプター (またはストア) に挿入できます。

// 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');
于 2013-11-05T23:32:06.443 に答える