W3cubDocs

/Ember.js

ContainerProxyMixin Class

PUBLIC

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

Module: ember-runtime

Given a fullName return a factory manager.

This method returns a manager which can be used for introspection of the factory's class or for the creation of factory instances with initial properties. The manager is an object with the following properties:

  • class - The registered or resolved class.
  • create - A function that will create an instance of the class with any dependencies injected.

For example:

let owner = Ember.getOwner(otherInstance);
// the owner is commonly the `applicationInstance`, and can be accessed via
// an instance initializer.

let factory = owner.factoryFor('service:bespoke');

factory.class;
// The registered or resolved class. For example when used with an Ember-CLI
// app, this would be the default export from `app/services/bespoke.js`.

let instance = factory.create({
  someProperty: 'an initial property value'
});
// Create an instance with any injections and the passed options as
// initial properties.

_lookupFactory (fullName) Anyprivate

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

Given a fullName return the corresponding factory.

Parameters:

fullName String

Returns:

Any

_resolveLocalLookupName (fullName, source) Stringprivate

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

Given a name and a source path, resolve the fullName

Parameters:

fullName String
source String

Returns:

String

lookup (fullName, options) Anypublic

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

Given a fullName return a corresponding instance.

The default behaviour 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

Parameters:

fullName String
options Object

Returns:

Any

ownerInjectionObjectpublic

Defined in packages/ember-runtime/lib/mixins/container_proxy.js:31
Available since 2.3.0

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' }
)

Returns:

Object

__container__Ember.Containerprivate

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

The container stores state.

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