register (fullName, factory, options) public
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:
let App = Ember.Application.create(); App.Orange = Ember.Object.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:
let App = Ember.Application.create(); let Session = Ember.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 = Ember.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:
let App = Ember.Application.create(); App.Person = Ember.Object.extend(); App.Orange = Ember.Object.extend(); App.Email = Ember.Object.extend(); App.session = Ember.Object.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 });
Parameters:
-
fullName
String
- type:name (e.g., 'model:user')
-
factory
Function
- (e.g., App.Person)
-
options
Object
- (optional) disable instantiation or singleton usage
Please login to continue.