Skip to main content
Version: 0.5.0

Binding

Represents a relation between an injectable element and a binding context. The binding contain things such as the scope of a service or the value of the service. Whenever a service is requested, its binding is read to know what to inject and how to inject the service. Any binding has these properties:

PropertyDescriptionType
idService id. Any attempt to create a service matching this service id is going to use this binding.number | string | symbol
tagsTags associated. Any attempt to create a service matching one of these tags is going to use this binding.number | string | symbol

There are two kinds of bindings:

TypeBinding

A class based binding. A type binding relies on a class constructor to instantiate the service.

PropertyDescriptionType
scopeBinding scope to determine wheter or not a service should be reused.BindingScope
typeClass to be used to call its constructorNewable

Binding scope

When the container creates an instance, it may reuse an existing instance instead if its scope allows it. These are the current scopes of a binding:

  • Transient: An instance of this service is never reused.
  • Request: An instance of this service is reused if service is requested under the same Container.get request.

Example: Given the services A, B and C, both A and B services depends on C. In addition, A services depends on B. If C is injected on request scope, a request to the A service results in the same C instance being injected to both A and B services.

  • Singleton: An instance of this service is always reused.