Class ApplicationInstance

The ApplicationInstance encapsulates all of the stateful aspects of a
running Application.

At a high-level, we break application boot into two distinct phases:

Definition time, where all of the classes, templates, and other
dependencies are loaded (typically in the browser).

Run time, where we begin executing the application once everything
has loaded.

Definition time can be expensive and only needs to happen once since it is
an idempotent operation. For example, between test runs and FastBoot
requests, the application stays the same. It is only the state that we want
to reset.

That state is what the ApplicationInstance manages: it is responsible for
creating the container that contains all application state, and disposing of
it once the particular test run or FastBoot request has finished.

Once you call this method, any time the key's value is set, your observer
will be notified. Note that the observers are triggered any time the
value is set, regardless of whether it has actually changed. Your
observer should be prepared to handle that.

The sender is the object that changed. The key is the property that
changes. The value property is currently reserved and unused. The rev
is the last property revision of the object when it changed, which you can
use to detect if the key value has really changed or not.

Usually you will not need the value or revision parameters at
the end. In this case, it is common to write observer methods that take
only a sender and key value as parameters or, if you aren't interested in
any of these values, to write an observer that has no parameters at all.

factoryFor
(fullName, options)
FactoryManagerpublic

This method returns a manager which can be used for introspection of the
factory's class or for the creation of factory instances with initial
properties. The manager is an object with the following properties:

class - The registered or resolved class.

create - A function that will create an instance of the class with
any dependencies injected.

For example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

import { getOwner } from '@ember/application';
let owner = getOwner(otherInstance);
// the owner is commonly the `applicationInstance`, and can be accessed via
// an instance initializer.
let factory = owner.factoryFor('service:bespoke');
factory.class;
// The registered or resolved class. For example when used with an Ember-CLI
// app, this would be the default export from `app/services/bespoke.js`.
let instance = factory.create({
someProperty: 'an initial property value'
});
// Create an instance with any injections and the passed options as
// initial properties.

When you call get on a computed property, the function will be
called and the return value will be returned instead of the function
itself.

Unknown Properties

Likewise, if you try to call get on a property whose value is
undefined, the unknownProperty() method will be called on the object.
If this method returns any value other than undefined, it will be returned
instead. This allows you to implement "virtual" properties that are
not defined upfront.

NOTE: If you do override init for a framework class like Ember.View,
be sure to call this._super(...arguments) in your
init declaration! If you don't, Ember may not have an opportunity to
do important setup work, and you'll see strange behavior in your
application.

It is important to note that injections can only be performed on
classes that are instantiated by Ember itself. Instantiating a class
directly (via create or new) bypasses the dependency injection
system.

Sometimes you need to change a value directly or indirectly without
actually calling get() or set() on it. In this case, you can use this
method instead. Calling this method will notify all observers that the
property has potentially changed value.

This method is generally very similar to calling object["key"] = value or
object.key = value, except that it provides support for computed
properties, the setUnknownProperty() method and property observers.

Computed Properties

If you try to set a value on a key that has a computed property handler
defined (see the get() method for an example), then set() will call
that method, passing both the value and key instead of simply changing
the value itself. This is useful for those times when you need to
implement a property that is composed of one or more member
properties.

Unknown Properties

If you try to set a value on a key that is undefined in the target
object, then the setUnknownProperty() handler will be called instead. This
gives you an opportunity to implement complex "virtual" properties that
are not predefined on the object. If setUnknownProperty() returns
undefined, then set() will simply set the value on the object.

Property Observers

In addition to changing the property, set() will also register a property
change with the object. Unless you have placed this call inside of a
beginPropertyChanges() and endPropertyChanges(), any "local" observers
(i.e. observer methods declared on the same object), will be called
immediately. Any "remote" observers (i.e. observer methods declared on
another object) will be placed in a queue and called at a later time in a
coalesced manner.