Class RegistryProxyMixin
privateRegistryProxyMixin is used to provide public access to specific registry functionality.
hasRegistration (fullName) Boolean public
Defined in packages/@ember/-internals/runtime/lib/mixins/registry_proxy.js:124
- fullName
- String
- returns
- Boolean
Check if a factory is registered.
register (fullName, factory, options) public
Defined in packages/@ember/-internals/runtime/lib/mixins/registry_proxy.js:31
- fullName
- String
type:name (e.g., 'model:user')
- factory
- Any
(e.g., App.Person)
- options
- Object
(optional) disable instantiation or singleton usage
Registers a factory that can be used for dependency injection (with
inject
) or for service lookup. Each factory is registered with
a full name including two parts: type:name
.
A simple example:
import Application from '@ember/application';
import EmberObject from '@ember/object';
let App = Application.create();
App.Orange = EmberObject.extend();
App.register('fruit:favorite', App.Orange);
Ember will resolve factories from the App
namespace automatically.
For example App.CarsController
will be discovered and returned if
an application requests controller:cars
.
An example of registering a controller with a non-standard name:
import Application from '@ember/application';
import Controller from '@ember/controller';
let App = Application.create();
let Session = Controller.extend();
App.register('controller:session', Session);
// The Session controller can now be treated like a normal controller,
// despite its non-standard name.
App.ApplicationController = Controller.extend({
needs: ['session']
});
Registered factories are instantiated by having create
called on them. Additionally they are singletons, each time
they are looked up they return the same instance.
Some examples modifying that default behavior:
import Application from '@ember/application';
import EmberObject from '@ember/object';
let App = Application.create();
App.Person = EmberObject.extend();
App.Orange = EmberObject.extend();
App.Email = EmberObject.extend();
App.session = EmberObject.create();
App.register('model:user', App.Person, { singleton: false });
App.register('fruit:favorite', App.Orange);
App.register('communication:main', App.Email, { singleton: false });
App.register('session', App.session, { instantiate: false });
registerOptions (fullName, options) public
Defined in packages/@ember/-internals/runtime/lib/mixins/registry_proxy.js:145
- fullName
- String
- options
- Object
Register options for a particular factory.
registerOptionsForType (type, options) public
Defined in packages/@ember/-internals/runtime/lib/mixins/registry_proxy.js:165
- type
- String
- options
- Object
Allow registering options for all factories of a type.
import Application from '@ember/application';
let App = Application.create();
let appInstance = App.buildInstance();
// if all of type `connection` must not be singletons
appInstance.registerOptionsForType('connection', { singleton: false });
appInstance.register('connection:twitter', TwitterConnection);
appInstance.register('connection:facebook', FacebookConnection);
let twitter = appInstance.lookup('connection:twitter');
let twitter2 = appInstance.lookup('connection:twitter');
twitter === twitter2; // => false
let facebook = appInstance.lookup('connection:facebook');
let facebook2 = appInstance.lookup('connection:facebook');
facebook === facebook2; // => false
registeredOption (fullName, optionName) Object public
Defined in packages/@ember/-internals/runtime/lib/mixins/registry_proxy.js:134
- fullName
- String
- optionName
- String
- returns
- Object
options
Return a specific registered option for a particular factory.
registeredOptions (fullName) Object public
Defined in packages/@ember/-internals/runtime/lib/mixins/registry_proxy.js:155
- fullName
- String
- returns
- Object
options
Return registered options for a particular factory.
registeredOptionsForType (type) Object public
Defined in packages/@ember/-internals/runtime/lib/mixins/registry_proxy.js:198
- type
- String
- returns
- Object
options
Return the registered options for all factories of a type.
resolveRegistration (fullName) Function public
Defined in packages/@ember/-internals/runtime/lib/mixins/registry_proxy.js:18
- fullName
- String
- returns
- Function
fullName's factory
Given a fullName return the corresponding factory.
unregister (fullName) public
Defined in packages/@ember/-internals/runtime/lib/mixins/registry_proxy.js:101
- fullName
- String
Unregister a factory.
import Application from '@ember/application';
import EmberObject from '@ember/object';
let App = Application.create();
let User = EmberObject.extend();
App.register('model:user', User);
App.resolveRegistration('model:user').create() instanceof User //=> true
App.unregister('model:user')
App.resolveRegistration('model:user') === undefined //=> true