PRIVATE
Defined in: packages/container/lib/registry.js:7
Module: ember
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.
Containerprivate
Creates a container based on this registry.
Object
Container Stringprivate
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.
String
String Stringprivate
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
String 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:
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
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
Booleanprivate
Given a fullName check if the container is aware of its factory or singleton instance.
Boolean Defines injection rules.
These rules are used to inject dependencies onto objects when they are instantiated.
Two forms of injections are possible:
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
String
Functionprivate
Any
String
Function Stringprivate
Normalize a fullName based on the application's conventions
String
String Stringprivate
A hook to enable custom fullName normalization behaviour
String
String String
Object
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
String
Object
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});
Functionprivate
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
Function 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
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
String
InheritingDictprivate
InheritingDictprivate
InheritingDictprivate
InheritingDictprivate
InheritingDictprivate
InheritingDictprivate
InheritingDictprivate
InheritingDictprivate
Registryprivate
A backup registry for resolving registrations when no matches can be found.
InheritingDictprivate
Resolverprivate
An object that has a resolve method that resolves a name.
© 2017 Yehuda Katz, Tom Dale and Ember.js contributors
Licensed under the MIT License.
http://emberjs.com/api/classes/Registry.html