Google News
logo
Aurelia - Interview Questions
What is Object lifetime in Aurelia?
Each object created by the dependency injection container has a "lifetime". There are three lifetime behaviors that are typical :
 
Container Singleton : A singleton class, A, is instantiated when it is first needed by the DI container. The container then holds a reference to class A's instance so that even if no other objects reference it, the container will keep it in memory. When any other class needs to inject A, the container will return the exact same instance. Thus, the instance of A has its lifetime connected to the container instance. It will not be garbage collected until the container itself is disposed and no other classes hold a reference to it.

Application Singleton : In Aurelia, it's possible to have child DI containers created from parent containers. Each of these child containers inherits the services of the parent, but can override them with their own registrations. Every application has a root DI container from which all classes and child containers are created. An application singleton is just like a container singleton, except that the instance is referenced by the root DI container in the application. This means that the root and all child containers will return the same singleton instance, provided that a child container doesn't explicitly override it with its own registration.

Transient : Any DI container can create transient instances. These instances are created each time they are needed. The container holds no references to them and always creates a new instance for each request.
Advertisement