W3cubDocs

/Ember.js

ContainerProxyMixin (public)

Defined in: packages/ember-runtime/lib/mixins/container_proxy.js:124
Module: ember

lookup (fullName, options) Any public

fullName
String
options
Object
returns
Any

Given a fullName return a corresponding instance.

The default behavior is for lookup to return a singleton instance. The singleton is scoped to the container, allowing multiple containers to all have their own locally scoped singletons.

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

registry.register('api:twitter', Twitter);

let twitter = container.lookup('api:twitter');

twitter instanceof Twitter; // => true

// by default the container will return singletons
let twitter2 = container.lookup('api:twitter');
twitter2 instanceof Twitter; // => true

twitter === twitter2; //=> true

If singletons are not wanted an optional flag can be provided at lookup.

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

registry.register('api:twitter', Twitter);

let twitter = container.lookup('api:twitter', { singleton: false });
let twitter2 = container.lookup('api:twitter', { singleton: false });

twitter === twitter2; //=> false

ownerInjection Object public

returns
Object

Returns an object that can be used to provide an owner to a manually created instance.

Example:

let owner = Ember.getOwner(this);

User.create(
  owner.ownerInjection(),
  { username: 'rwjblue' }
)

© 2017 Yehuda Katz, Tom Dale and Ember.js contributors
Licensed under the MIT License.
https://emberjs.com/api/ember/2.15/classes/ContainerProxyMixin/methods