Knowing when your are in an injection context, will allow you to use the [`inject`](api/core/inject) function to inject instances.
## Class constructors
Everytime the DI system instantiates a class, this is done in an injection context. This is being handled by the framework itself. The constructor of the class is executed in that runtime context thus allowing to inject a token using the [`inject`](api/core/inject) function.
<code-examplelanguage="typescript">
class MyComponent {
private service1: Service1;
private service2: Service2 = inject(Service2); // In context
constructor() {
this.service1 = inject(HeroService) // In context
}
}
</code-example>
## Stack frame in context
Some APIs are designed to be run in an injection context. This is the case, for example, of the router guards. It allows the use of [`inject`](api/core/inject) to access a service within the guard function.