为什么我必须在我的简单授权自定义会话中查找存储而不是将其作为服务注入?

Why must I lookup store on my simple-auth custom session instead of injecting it as a service?

我有一个这样的初始化程序:

import Ember from 'ember';
import Session from 'simple-auth/session';

var SessionWithCurrentUser = Session.extend({
  store: Ember.inject.service(),
  currentUser: function() {
    console.log(this.get('store'));
    console.log(this.store);
    console.log(this.container.lookup('service:store'));
  }.property('secure.access_token')
});

export default {
  name: 'custom-session',
  after: 'ember-data',
  initialize(registry) {
    registry.register('session:withCurrentUser', SessionWithCurrentUser);
  }
};

currentUser 在我的应用程序完成加载很久之后在用户交互时被调用。只有最后一个容器查找给出了store,另外2个是对象:

{
 _lastData: Object,
 key: "ember_simple_auth:session"
 [..]
}

这是怎么回事?为什么我不能注入商店?

这是因为当前版本的 simple-auth 中的存储被具有会话存储的实例初始化程序覆盖。 simple-auth 的下一个主要版本会将会话存储变成一项服务,我们将能够做到:

import Ember from 'ember';

const { service } = Ember.inject;

export default Ember.Service.extend({
  session: service('session'),
  store: Ember.inject.service(),

  account: Ember.computed('session.content.secure.account_id', function() {
    const accountId = this.get('session.content.secure.account_id');
    if (!Ember.isEmpty(accountId)) {
      return DS.PromiseObject.create({
        promise: this.get('store').find('account', accountId)
      });
    }
  })
});

the dummy app, once https://github.com/simplabs/ember-simple-auth/pull/602合并。