API REFERENCE
Provider
import { Provider } from '@rasenganjs/server';
Abstract base class for dependency-injectable classes that want lifecycle hooks. See Lifecycle Hooks for the full explanation of when each hook fires and why every provider is resolved eagerly at boot.
abstract class Provider { onInit?(): void | Promise<void>; onDestroy?(): void | Promise<void>; }
Both hooks are optional — a Provider subclass that implements neither behaves exactly like a plain class as far as the DI container is concerned.
Extending Provider Is Opt-in
Any class is a valid DI provider (see ProviderLike) — extending Provider only matters if you need onInit()/onDestroy(). A plain UserService class with no lifecycle needs works fine as a provider without extending anything.
import { Provider } from '@rasenganjs/server'; export class DatabaseService extends Provider { connection?: Connection; async onInit() { this.connection = await createConnection(process.env.DATABASE_URL); } async onDestroy() { await this.connection?.close(); } }
export default defineModule({ providers: [DatabaseService], exports: [DatabaseService], });
Who Else Extends It
Gateway (@rasenganjs/ws) and Queue (@rasenganjs/queue) both extend Provider — that's exactly why a gateway or queue's onInit()/onDestroy() fire like any other provider's, and why they can be exported from a module for another module to inject the same instance.
