Plugin interface for extending Stratix applications.
Plugins follow a lifecycle: initialize → start → stop
class DatabasePlugin implements Plugin { readonly metadata: PluginMetadata = { name: 'database', description: 'PostgreSQL database plugin', dependencies: ['logger'] }; private database?: Database; async initialize(context: PluginContext): Promise<void> { const config = context.getConfig<DatabaseConfig>(); this.database = new Database(config); context.container.register('database', () => this.database, { lifetime: ServiceLifetime.SINGLETON }); } async start(): Promise<void> { await this.database?.connect(); } async stop(): Promise<void> { await this.database?.disconnect(); } async healthCheck(): Promise<HealthCheckResult> { return await this.database?.ping(); }} Copy
class DatabasePlugin implements Plugin { readonly metadata: PluginMetadata = { name: 'database', description: 'PostgreSQL database plugin', dependencies: ['logger'] }; private database?: Database; async initialize(context: PluginContext): Promise<void> { const config = context.getConfig<DatabaseConfig>(); this.database = new Database(config); context.container.register('database', () => this.database, { lifetime: ServiceLifetime.SINGLETON }); } async start(): Promise<void> { await this.database?.connect(); } async stop(): Promise<void> { await this.database?.disconnect(); } async healthCheck(): Promise<HealthCheckResult> { return await this.database?.ping(); }}
Optional
Initializes the plugin.
Called during application startup, after all dependencies are initialized. Register services in the container during this phase.
The plugin context
async initialize(context: PluginContext): Promise<void> { const database = new Database(context.getConfig()); context.container.register('database', () => database);} Copy
async initialize(context: PluginContext): Promise<void> { const database = new Database(context.getConfig()); context.container.register('database', () => database);}
Starts the plugin.
Called after all plugins are initialized, before the application starts. Connect to external resources during this phase.
async start(): Promise<void> { await this.database.connect(); console.log('Database connected');} Copy
async start(): Promise<void> { await this.database.connect(); console.log('Database connected');}
Stops the plugin.
Called during application shutdown, in reverse dependency order. Close connections and clean up resources during this phase.
async stop(): Promise<void> { await this.database.disconnect(); console.log('Database disconnected');} Copy
async stop(): Promise<void> { await this.database.disconnect(); console.log('Database disconnected');}
Performs a health check for the plugin.
The health check result
async healthCheck(): Promise<HealthCheckResult> { try { await this.database.ping(); return { status: HealthStatus.UP }; } catch (error) { return { status: HealthStatus.DOWN, message: error.message }; }} Copy
async healthCheck(): Promise<HealthCheckResult> { try { await this.database.ping(); return { status: HealthStatus.UP }; } catch (error) { return { status: HealthStatus.DOWN, message: error.message }; }}
Readonly
Plugin metadata (name, dependencies).
Plugin interface for extending Stratix applications.
Plugins follow a lifecycle: initialize → start → stop
Example