↓ Ir para o conteúdo principal

← todas as notas

📎 Webclip

Dependency injection in Ember.js - Going deeper

The post expands on Ember’s internal dependency injection setup. It shows where the app container is created, how objects from the container can access it, and how public APIs can replace direct use of the private __container__ property.

Reading notes
#

  • Ember creates an internal container when an app starts, and that container is the basis for its dependency setup.
  • optionsForType can define lookup behavior for a type, such as making components and views non-singletons.
  • The default for singleton behavior is true, so container.register('store:main', Store, { singleton: true }) matches application.register('store', Store).
  • Objects created by the container have a container property, which lets routes call this.container.lookup without relying on __container__.
  • instantiate: false is used for templates and helpers, since they are functions and do not need instantiation.
  • container.lookup first returns a cached singleton if one exists, then instantiates the requested full name, caches it if needed, and finally returns the result.
  • container.lookup also checks that the full name follows the type:name syntax before doing the lookup.