Creating an Application
Use thecreateApp function to create and initialize a new application instance:
App Class
TheApp class is the main application container. It’s created internally by createApp and provides:
Properties
name: string- Application namedebug: boolean- Debug mode flagtimezone: string- Application timezoneemitter: Emitter- Event emitter instance for app-wide events$: E- Exposed services object (based on theexposeconfiguration)
Methods
get<T>(token: Token<T>): T
Resolve a service from the dependency injection container:
async run(): Promise<void>
Start the application by executing all extension bootstrap functions and emitting the app:ready event:
The
run() method can be called multiple times safely - bootstrap functions will only execute once.async dispose(): Promise<void>
Clean up the application by disposing all services and removing all event listeners:
dispose() method will be automatically cleaned up.
Path Resolvers
rootPath(...paths: string[]): string
Resolve paths relative to the application root directory:
runtimePath(...paths: string[]): string
Resolve paths relative to the runtime directory:
AppContext Interface
TheAppContext is passed to extension bootstrap functions and provides access to core app functionality:
Using AppContext in Extensions
Exposing Services
Theexpose option allows you to expose specific services on the app’s $ property with full type safety:
Lifecycle
The application lifecycle follows this sequence:-
Construction -
new App(options)is called internally- Container is created
- Extensions are processed and providers are registered
- Bootstrap functions are collected
-
Initialization -
await app.init()- Exposed services are resolved and assigned to
app.$
- Exposed services are resolved and assigned to
-
Running -
await app.run()- All extension bootstrap functions execute in parallel
app:readyevent is emitted
-
Disposal -
await app.dispose()- All singletons with
dispose()methods are cleaned up - All event listeners are removed
- All singletons with