App Startup Customization
VonaJS provides a Hook/Monkey mechanism that allows deep customization of the system during application startup
TIP
Of course, for regular business needs, it is generally sufficient to just create a Startup
Before explaining the Hook/Monkey mechanism, it is necessary to first understand the timing of application startup and shutdown
Application Startup Timing

The application startup timing is divided into four steps:
appLoad: Loads all modules. For each module, it triggers the hooksmoduleLoading,configLoaded, andmoduleLoadedappStart: Triggers the hookappStart. For example, the module a-startup responds to this hook and executesapp startups(after: false). See: Startup- After
appStartis executed, it setsapp.meta.appReady=true - At this point, all API services provided by the system can accept client requests
- After
appReady: Triggers the hookappReady. For example, the module a-startup responds to this hook and executesapp startups(after: true). See: StartupappStarted: Triggers the hookappStarted
Application Shutdown Timing

The application shutdown timing is divided into two steps:
appClose: Triggers the hookappCloseappClosed: Triggers the hookappClosed
Hook List
The system provides three scenarios to respond to application startup/shutdown hooks:
Module Main: Respond to the module's own hooks in the module codeModule Monkey: Respond to system hooks in the module codeApp Monkey: Respond to system hooks in the app code
For different scenarios, corresponding interface definitions are provided for different hooks, thereby standardizing the use of hooks
| Hook | Module Main Interface | Module Monkey Interface | App Monkey Interface |
|---|---|---|---|
| moduleLoading | IModuleMain | IMonkeyModule | IMonkeyModule |
| configLoaded | IModuleMain | IMonkeyModule | IMonkeyModule |
| moduleLoaded | IModuleMain | IMonkeyModule | IMonkeyModule |
| appStart | IMonkeySystem / IMonkeyAppStart | IMonkeySystem / IMonkeyAppStart | |
| appReady | IMonkeySystem / IMonkeyAppReady | IMonkeySystem / IMonkeyAppReady | |
| appStarted | IMonkeySystem / IMonkeyAppStarted | IMonkeySystem / IMonkeyAppStarted | |
| appClose | IMonkeySystem / IMonkeyAppClose | IMonkeySystem / IMonkeyAppClose | |
| appClosed | IMonkeySystem / IMonkeyAppClosed | IMonkeySystem / IMonkeyAppClosed |
Create Module Main
1. Cli command
$ vona :init:main demo-student2. Menu command
TIP
Context Menu - [Module Path]: Vona Init/Main
Module Main Definition
export class Main extends BeanSimple implements IModuleMain {
async moduleLoading() {}
async moduleLoaded() {}
async configLoaded(_config: any) {}
}Create Module Monkey
1. Cli command
$ vona :init:monkey demo-student2. Menu command
TIP
Context Menu - [Module Path]: Vona Init/Monkey
Module Monkey Definition
export class Monkey extends BeanSimple implements IMonkeyModule, IMonkeySystem {
async moduleLoading(_module: IModule) {}
async moduleLoaded(_module: IModule) {}
async configLoaded(_module: IModule, _config: any) {}
async appStart() {}
async appReady() {}
async appStarted() {}
async appClose() {}
async appClosed() {}
}Create App Monkey
1. Cli command
$ vona :init:appMonkey2. Menu command
TIP
Context Menu - [Project Path/src]: Vona Init/App Monkey
App Monkey Definition
src/backend/config/monkey.ts
export class AppMonkey extends BeanSimple implements IMonkeyModule, IMonkeySystem {
async moduleLoading(_module: IModule) {}
async moduleLoaded(_module: IModule) {}
async configLoaded(_module: IModule, _config: any) {}
async appStart() {}
async appReady() {}
async appStarted() {}
async appClose() {}
async appClosed() {}
}