#

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

# Registry Class

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

Available since 1.11.0

A registry used to store factory and option information keyed by type.

A `Registry` stores the factory and option information needed by a `Container` to instantiate and cache objects.

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

- Index
- Methods
- Properties

## Item Index

### Methods

- container
- describe
- expandLocalLookup
- factoryInjection
- factoryTypeInjection
- has
- injection
- knownForType
- makeToString
- normalize
- normalizeFullName
- options
- optionsForType
- register
- resolve
- typeInjection
- unregister

### Properties

- _factoryInjections
- _factoryTypeInjections
- _injections
- _normalizeCache
- _options
- _resolveCache
- _typeInjections
- _typeOptions
- fallback
- registrations
- resolver

## Methods

### `container`

(

- `options`

)
Container private

Defined in `packages/container/lib/registry.js:137`

Creates a container based on this registry.

#### Parameters:

- `options` Object

#### Returns:

Container:

created container

### `describe`

(

- `fullName`

)
String private

Defined in `packages/container/lib/registry.js:260`

A hook that can be used to describe how the resolver will attempt to find the factory.

For example, the default Ember `.describe` returns the full class name (including namespace) where Ember's resolver expects to find the `fullName`.

#### Parameters:

- `fullName` String

#### Returns:

String:

described fullName

### `expandLocalLookup`

(

- `fullName`
- `[options]`

)
String private

Defined in `packages/container/lib/registry.js:776`

Given a fullName and a source fullName returns the fully resolved fullName. Used to allow for local lookup.

    let registry = new Registry();

    // the twitter factory is added to the module system
    registry.expandLocalLookup('component:post-title', { source: 'template:post' }) // => component:post/post-title

#### Parameters:

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

    the fullname of the request source (used for local lookups)

#### Returns:

String:

fullName

### `factoryInjection`

(

- `factoryName`
- `property`
- `injectionName`

)
private

Defined in `packages/container/lib/registry.js:592`

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

### `factoryTypeInjection`

(

- `type`
- `property`
- `fullName`

)
private

Defined in `packages/container/lib/registry.js:553`

Used only via `factoryInjection`.

Provides a specialized form of injection, specifically enabling all factory of one type to be injected with a reference to another object.

For example, provided each factory of type `model` needed a `store`. one would do the following:

    let registry = new Registry();

    registry.register('store:main', SomeStore);

    registry.factoryTypeInjection('model', 'store', 'store:main');

    let store = registry.lookup('store:main');
    let UserFactory = registry.lookupFactory('model:user');

    UserFactory.store instanceof SomeStore; //=> true

#### Parameters:

- `type` String
- `property` String
- `fullName` String

### `has`

(

- `fullName`
- `[options]`

)
Boolean private

Defined in `packages/container/lib/registry.js:333`

Given a fullName check if the container is aware of its factory or singleton instance.

#### Parameters:

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

    the fullname of the request source (used for local lookups)

#### Returns:

Boolean:

### `injection`

(

- `factoryName`
- `property`
- `injectionName`

)
private

Defined in `packages/container/lib/registry.js:486`

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

### `knownForType`

(

- `type`

)
private

Defined in `packages/container/lib/registry.js:661`

#### Parameters:

- `type` String

  the type to iterate over

### `makeToString`

(

- `factory`
- `fullName`

)
Function private

Defined in `packages/container/lib/registry.js:315`

#### Parameters:

- `factory` Any
- `fullName` String

#### Returns:

Function:

toString function

### `normalize`

(

- `fullName`

)
String private

Defined in `packages/container/lib/registry.js:301`

Normalize a fullName based on the application's conventions

#### Parameters:

- `fullName` String

#### Returns:

String:

normalized fullName

### `normalizeFullName`

(

- `fullName`

)
String private

Defined in `packages/container/lib/registry.js:283`

A hook to enable custom fullName normalization behaviour

#### Parameters:

- `fullName` String

#### Returns:

String:

normalized fullName

### `options`

(

- `fullName`
- `options`

)
private

Defined in `packages/container/lib/registry.js:395`

#### Parameters:

- `fullName` String
- `options` Object

### `optionsForType`

(

- `type`
- `options`

)
private

Defined in `packages/container/lib/registry.js:354`

Allow registering options for all factories of a type.

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

    // if all of type connection must not be singletons
    registry.optionsForType('connection', { singleton: false });

    registry.register('connection:twitter', TwitterConnection);
    registry.register('connection:facebook', FacebookConnection);

    let twitter = container.lookup('connection:twitter');
    let twitter2 = container.lookup('connection:twitter');

    twitter === twitter2; // => false

    let facebook = container.lookup('connection:facebook');
    let facebook2 = container.lookup('connection:facebook');

    facebook === facebook2; // => false

#### Parameters:

- `type` String
- `options` Object

### `register`

(

- `fullName`
- `factory`
- `options`

)
private

Defined in `packages/container/lib/registry.js:149`

Registers a factory for later injection.

Example:

    let registry = new Registry();

    registry.register('model:user', Person, {singleton: false });
    registry.register('fruit:favorite', Orange);
    registry.register('communication:main', Email, {singleton: false});

#### Parameters:

- `fullName` String
- `factory` Function
- `options` Object

### `resolve`

(

- `fullName`
- `[options]`

)
Function private

Defined in `packages/container/lib/registry.js:216`

Given a fullName return the corresponding factory.

By default `resolve` will retrieve the factory from the registry.

    let registry = new Registry();
    registry.register('api:twitter', Twitter);

    registry.resolve('api:twitter') // => Twitter

Optionally the registry can be provided with a custom resolver. If provided, `resolve` will first provide the custom resolver the opportunity to resolve the fullName, otherwise it will fallback to the registry.

    let registry = new Registry();
    registry.resolver = function(fullName) {
       // lookup via the module system of choice
     };

    // the twitter factory is added to the module system
    registry.resolve('api:twitter') // => Twitter

#### Parameters:

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

    the fullname of the request source (used for local lookups)

#### Returns:

Function:

fullName's factory

### `typeInjection`

(

- `type`
- `property`
- `fullName`

)
private

Defined in `packages/container/lib/registry.js:433`

Used only via `injection`.

Provides a specialized form of injection, specifically enabling all objects of one type to be injected with a reference to another object.

For example, provided each object of type `controller` needed a `router`. one would do the following:

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

    registry.register('router:main', Router);
    registry.register('controller:user', UserController);
    registry.register('controller:post', PostController);

    registry.typeInjection('controller', 'router', 'router:main');

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

    user.router instanceof Router; //=> true
    post.router instanceof Router; //=> true

    // both controllers share the same router
    user.router === post.router; //=> true

#### Parameters:

- `type` String
- `property` String
- `fullName` String

### `unregister`

(

- `fullName`

)
private

Defined in `packages/container/lib/registry.js:186`

Unregister a fullName

    let registry = new Registry();
    registry.register('model:user', User);

    registry.resolve('model:user').create() instanceof User //=> true

    registry.unregister('model:user')
    registry.resolve('model:user') === undefined //=> true

#### Parameters:

- `fullName` String

## Properties

### `_factoryInjections`

InheritingDict private

Defined in `packages/container/lib/registry.js:97`

### `_factoryTypeInjections`

InheritingDict private

Defined in `packages/container/lib/registry.js:89`

### `_injections`

InheritingDict private

Defined in `packages/container/lib/registry.js:81`

### `_normalizeCache`

InheritingDict private

Defined in `packages/container/lib/registry.js:105`

### `_options`

InheritingDict private

Defined in `packages/container/lib/registry.js:121`

### `_resolveCache`

InheritingDict private

Defined in `packages/container/lib/registry.js:113`

### `_typeInjections`

InheritingDict private

Defined in `packages/container/lib/registry.js:73`

### `_typeOptions`

InheritingDict private

Defined in `packages/container/lib/registry.js:129`

### `fallback`

Registry private

Defined in `packages/container/lib/registry.js:48`

A backup registry for resolving registrations when no matches can be found.

### `registrations`

InheritingDict private

Defined in `packages/container/lib/registry.js:66`

### `resolver`

Resolver private

Defined in `packages/container/lib/registry.js:57`

An object that has a `resolve` method that resolves a name.