#

API Docs for: v2.11.1
Show: Inherited Protected Private Deprecated

# Container Class

Defined in: `packages/container/lib/container.js:7`
Module: ember

A container used to instantiate and cache objects.

Every `Container` must be associated with a `Registry`, which is referenced to determine the factory and options that should be used to instantiate objects.

The public API for `Container` is still in flux and should not be considered stable.

- Index
- Methods
- Properties

## Item Index

### Methods

- destroy
- lookup
- lookupFactory
- ownerInjection
- reset

### Properties

- cache
- factoryCache
- owner
- registry
- validationCache

## Methods

### `destroy`

() private

Defined in `packages/container/lib/container.js:133`

A depth first traversal, destroying the container, its descendant containers and all their managed objects.

### `lookup`

(

- `fullName`
- `[options]`

)
Any private

Defined in `packages/container/lib/container.js:68`

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 optional
  - `[source]` String optional

    The fullname of the request source (used for local lookup)

#### Returns:

Any:

### `lookupFactory`

(

- `fullName`
- `[options]`

)
Any private

Defined in `packages/container/lib/container.js:118`

Given a fullName, return the corresponding factory.

#### Parameters:

- `fullName` String
- `[options]` Object optional
  - `[source]` String optional

    The fullname of the request source (used for local lookup)

#### Returns:

Any:

### `ownerInjection`

() Object private

Defined in `packages/container/lib/container.js:165`

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

#### Returns:

Object:

### `reset`

(

- `fullName`

)
private

Defined in `packages/container/lib/container.js:150`

Clear either the entire cache or just the cache for a particular key.

#### Parameters:

- `fullName` String

  optional key to reset; if missing, resets everything

## Properties

### `cache`

InheritingDict private

Defined in `packages/container/lib/container.js:47`

### `factoryCache`

InheritingDict private

Defined in `packages/container/lib/container.js:54`

### `owner`

Object private

Defined in `packages/container/lib/container.js:32`

### `registry`

Registry private

Defined in `packages/container/lib/container.js:39`

Available since 1.11.0

### `validationCache`

InheritingDict private

Defined in `packages/container/lib/container.js:61`