Registry#injection()

injection (factoryName, property, injectionName) private

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

Defines injection rules.

These rules are used to inject dependencies onto objects when they are instantiated.

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('source:main', Source);
registry.register('model:user', User);
registry.register('model:post', Post);

// injecting one fullName on another fullName
// eg. each user model gets a post model
registry.injection('model:user', 'post', 'model:post');

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

let user = container.lookup('model:user');
let post = container.lookup('model:post');

user.source instanceof Source; //=> true
post.source instanceof Source; //=> true

user.post instanceof Post; //=> true

// and both models share the same source
user.source === post.source; //=> true

Parameters:

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

Please login to continue.