How to configure Singleton with ember-cli initializers?

With ember-cli providing injectors for DI, I have something like this in my file app/initializers/drupal-csrf-token.js:

export default {
  name: 'drupal-csrf-token',

  initialize: function(container, app) {
    app.inject('route', 'drupalCsrfToken', 'service:drupalCsrfToken');
    app.inject('controller', 'drupalCsrfToken', 'service:drupalCsrfToken');
  }
};

Usually, when you want a singleton with DI, you do something like this:

container.register('store:main', Store, { singleton: true });

However, I cannot figure out where to bind the singleton flag to the initializer so that it gets stuck.

Is it possible?

+4
source share
1 answer

You can do this inside your initialization method, I suppose:

  app.register('service:drupalCsrfToken', 'drupal-csrf-token', { singleton: true });

I think singleton is true by default.

+1
source

All Articles