Registry#factoryInjection()

factoryInjection (factoryName, property, injectionName) private

Defined in packages/container/lib/registry.js:594

Defines factory injection rules.

Similar to regular injection rules, but are run against factories, via Registry#lookupFactory.

These rules are used to inject objects onto factories when they are looked up.

Two forms of injections are possible:

  • Injecting one fullName on another fullName
  • Injecting one fullName on a type

Example:

let registry = new Registry();
let container = registry.container();

registry.register('store:main', Store);
registry.register('store:secondary', OtherStore);
registry.register('model:user', User);
registry.register('model:post', Post);

// injecting one fullName on another type
registry.factoryInjection('model', 'store', 'store:main');

// injecting one fullName on another fullName
registry.factoryInjection('model:post', 'secondaryStore', 'store:secondary');

let UserFactory = container.lookupFactory('model:user');
let PostFactory = container.lookupFactory('model:post');
let store = container.lookup('store:main');

UserFactory.store instanceof Store; //=> true
UserFactory.secondaryStore instanceof OtherStore; //=> false

PostFactory.store instanceof Store; //=> true
PostFactory.secondaryStore instanceof OtherStore; //=> true

// and both models share the same source instance
UserFactory.store === PostFactory.store; //=> true

Parameters:

factoryName String
property String
injectionName String
doc_EmberJs
2016-11-30 16:52:54
Comments
Leave a Comment

Please login to continue.