Back to Cherry Studio

Lifecycle Module

src/main/core/lifecycle/README.md

2.0.01.8 KB
Original Source

Lifecycle Module

IoC container + service lifecycle management with phased bootstrap and parallel initialization.

Full documentation has moved to docs/references/lifecycle/. This file is a quick-reference pointer.

TopicReference Doc
Decision: lifecycle vs singleton?Decision Guide
Architecture: phases, hooks, statesLifecycle Overview
Application: bootstrap, shutdown, registryApplication Overview
Usage: decorators, error handling, platformUsage Guide
Migrating old servicesMigration Guide

File Structure

lifecycle/
├── types.ts              # Phase, LifecycleState, ServiceMetadata, Pausable, errors
├── decorators.ts         # @Injectable, @ServicePhase, @DependsOn, @Priority, etc.
├── BaseService.ts        # Abstract base class with lifecycle hooks
├── event.ts              # Emitter<T>, Event<T>, Disposable — typed inter-service events
├── signal.ts             # Signal<T> — one-shot deferred value (PromiseLike)
├── ServiceContainer.ts   # IoC container with DI and conditional activation
├── DependencyResolver.ts # Topological sort, layered parallel resolution
├── LifecycleManager.ts   # Phased bootstrap, shutdown, pause/resume/stop/start
├── index.ts              # Barrel export
└── __tests__/            # Unit tests for all components