# Hooks

Ts.ED emit different events during it's initialization phase (lifecycle). This lifecycle hooks that provide visibility into these key life moments and the ability to act when they occur.

This schemes resume the order of hooks regarding to ServerLoader and Providers:

Open in fullscreen

# Examples

Hooks can be used on ServerLoader or on your Provider:

import {ServerLoader} from "@tsed/common";

class Server extends ServerLoader implements BeforeInit {
  async $beforeInit(): Promise<any>  {
    
  }
}
1
2
3
4
5
6
7
import {Injectable, BeforeInit} from "@tsed/common";

@Injectable()
export class MyService implements BeforeInit  {
  async $beforeInit(): Promise<any>  {
    
  }
}
1
2
3
4
5
6
7
8

Note

Database connection can be performed with Asynchronous Provider since v5.26. See custom providers