### Real-world ts5deco Application Setup Source: https://github.com/yoonhogo/ts5deco/blob/main/packages/inject/README.md A comprehensive example demonstrating the setup of a ts5deco application, including defining tokens, interfaces, services (Logger, Database, User), registering values and bindings, and resolving services. ```typescript import { Container, Injectable, Inject, createMetadataKey, PostConstruct } from 'ts5deco-inject'; // Tokens const CONFIG = createMetadataKey('config'); const LOGGER = createMetadataKey('logger'); const DATABASE = createMetadataKey('database'); // Configuration interface AppConfig { port: number; dbUrl: string; logLevel: string; } // Logger service interface Logger { info(message: string): void; error(message: string): void; } @Injectable() class ConsoleLogger implements Logger { @Inject(CONFIG) private config!: AppConfig; info(message: string) { if (this.config.logLevel === 'info') { console.log(`[INFO] ${message}`); } } error(message: string) { console.error(`[ERROR] ${message}`); } } // Database service interface Database { connect(): Promise; query(sql: string): Promise; } @Injectable() class PostgresDatabase implements Database { @Inject(CONFIG) private config!: AppConfig; @Inject(LOGGER) private logger!: Logger; @PostConstruct async initialize() { await this.connect(); } async connect() { this.logger.info(`Connecting to ${this.config.dbUrl}`); // Connection logic here } async query(sql: string) { this.logger.info(`Executing: ${sql}`); // Query logic here return []; } } // Business service @Injectable() class UserService { @Inject(DATABASE) private db!: Database; @Inject(LOGGER) private logger!: Logger; async getUser(id: string) { this.logger.info(`Fetching user ${id}`); return await this.db.query(`SELECT * FROM users WHERE id = $1`); } async createUser(userData: any) { this.logger.info(`Creating user ${userData.email}`); return await this.db.query(`INSERT INTO users ...`); } } // Setup container const container = new Container(); const config: AppConfig = { port: 3000, dbUrl: 'postgresql://localhost:5432/myapp', logLevel: 'info' }; container.register({ type: 'value', token: CONFIG, useValue: config }); container.bind(LOGGER).to(ConsoleLogger).inSingletonScope(); container.bind(DATABASE).to(PostgresDatabase).inSingletonScope(); container.bind(UserService).toSelf().inSingletonScope(); // Use the application const userService = container.resolve(UserService); const user = await userService.getUser('123'); // Cleanup when done await container.dispose(); ``` -------------------------------- ### Quick Start: Basic DI setup with ts5deco-inject Source: https://github.com/yoonhogo/ts5deco/blob/main/packages/inject/README.md Demonstrates a basic setup for dependency injection using ts5deco-inject. It shows defining services with decorators, registering them in a container, and resolving them for use. ```typescript import { Container, Injectable, Inject, createMetadataKey } from 'ts5deco-inject'; // Define a metadata key for type-safe injection const DATABASE_URL = createMetadataKey('database.url'); @Injectable() class DatabaseService { @Inject(DATABASE_URL) private url!: string; connect() { console.log(`Connecting to ${this.url}`); } } @Injectable() class UserService { @Inject(DatabaseService) private db!: DatabaseService; getUser(id: string) { this.db.connect(); return { id, name: 'John Doe' }; } } // Create container and register services const container = new Container(); container.register({ type: 'value', token: DATABASE_URL, useValue: 'postgresql://localhost:5432/mydb' }); container.register({ type: 'class', token: DatabaseService, useClass: DatabaseService }); container.register({ type: 'class', token: UserService, useClass: UserService }); // Resolve and use services const userService = container.resolve(UserService); const user = userService.getUser('123'); console.log(user); // { id: '123', name: 'John Doe' } ``` -------------------------------- ### Real-world Example: Dependency Injection Setup Source: https://github.com/yoonhogo/ts5deco/blob/main/packages/inject/docs/index.html A comprehensive example demonstrating setting up a container, defining tokens, creating injectable services (Logger, Database, UserService), injecting dependencies, and resolving services. ```TypeScript import { Container, Injectable, Inject, createMetadataKey, PostConstruct } from '@ts5deco/inject'; // Tokens const CONFIG = createMetadataKey('config'); const LOGGER = createMetadataKey('logger'); const DATABASE = createMetadataKey('database'); // Configuration interface AppConfig { port: number; dbUrl: string; logLevel: string; } // Logger service interface Logger { info(message: string): void; error(message: string): void; } @Injectable() class ConsoleLogger implements Logger { @Inject(CONFIG) private config!: AppConfig; info(message: string) { if (this.config.logLevel === 'info') { console.log(`[INFO] ${message}`); } } error(message: string) { console.error(`[ERROR] ${message}`); } } // Database service interface Database { connect(): Promise; query(sql: string): Promise; } @Injectable() class PostgresDatabase implements Database { @Inject(CONFIG) private config!: AppConfig; @Inject(LOGGER) private logger!: Logger; @PostConstruct async initialize() { await this.connect(); } async connect() { this.logger.info(`Connecting to ${this.config.dbUrl}`); // Connection logic here } async query(sql: string) { this.logger.info(`Executing: ${sql}`); // Query logic here return []; } } // Business service @Injectable() class UserService { @Inject(DATABASE) private db!: Database; @Inject(LOGGER) private logger!: Logger; async getUser(id: string) { this.logger.info(`Fetching user ${id}`); return await this.db.query(`SELECT * FROM users WHERE id = $1`); } async createUser(userData: any) { this.logger.info(`Creating user ${userData.email}`); return await this.db.query(`INSERT INTO users ...`); } } // Setup container const container = new Container(); const config: AppConfig = { port: 3000, dbUrl: 'postgresql://localhost:5432/myapp', logLevel: 'info' }; container.register({ type: 'value', token: CONFIG, useValue: config }); container.bind(LOGGER).to(ConsoleLogger).inSingletonScope(); container.bind(DATABASE).to(PostgresDatabase).inSingletonScope(); container.bind(UserService).toSelf().inSingletonScope(); // Use the application const userService = container.resolve(UserService); const user = await userService.getUser('123'); // Cleanup when done await container.dispose(); ``` -------------------------------- ### Quick Start Example Source: https://github.com/yoonhogo/ts5deco/blob/main/packages/inject/docs/index.html Demonstrates setting up a dependency injection container, registering services (DatabaseService, UserService), and resolving a service to use its functionality. It showcases type-safe injection using metadata keys and decorators. ```typescript import { Container, Injectable, Inject, createMetadataKey } from '@ts5deco/inject'; // Define a metadata key for type-safe injection const DATABASE_URL = createMetadataKey('database.url'); @Injectable() class DatabaseService { @Inject(DATABASE_URL) private url!: string; connect() { console.log(`Connecting to ${this.url}`); } } @Injectable() class UserService { @Inject(DatabaseService) private db!: DatabaseService; getUser(id: string) { this.db.connect(); return { id, name: 'John Doe' }; } } // Create container and register services const container = new Container(); container.register({ type: 'value', token: DATABASE_URL, useValue: 'postgresql://localhost:5432/mydb' }); container.register({ type: 'class', token: DatabaseService, useClass: DatabaseService }); container.register({ type: 'class', token: UserService, useClass: UserService }); // Resolve and use services const userService = container.resolve(UserService); const user = userService.getUser('123'); console.log(user); // { id: '123', name: 'John Doe' } ``` -------------------------------- ### Quick Start: Dependency Injection Example Source: https://github.com/yoonhogo/ts5deco/blob/main/packages/inject/README-ko.md Demonstrates a basic setup for dependency injection using ts5deco-inject. It shows how to define services with decorators, register them in a container, and resolve them for use, illustrating type-safe injection with metadata keys. ```typescript import { Container, Injectable, Inject, createMetadataKey } from 'ts5deco-inject'; // 타입 안전한 주입을 위한 메타데이터 키 정의 const DATABASE_URL = createMetadataKey('database.url'); @Injectable() class DatabaseService { @Inject(DATABASE_URL) private url!: string; connect() { console.log(`${this.url}에 연결 중`); } } @Injectable() class UserService { @Inject(DatabaseService) private db!: DatabaseService; getUser(id: string) { this.db.connect(); return { id, name: '홍길동' }; } } // 컨테이너 생성 및 서비스 등록 const container = new Container(); container.register({ type: 'value', token: DATABASE_URL, useValue: 'postgresql://localhost:5432/mydb' }); container.register({ type: 'class', token: DatabaseService, useClass: DatabaseService }); container.register({ type: 'class', token: UserService, useClass: UserService }); // 서비스 해결 및 사용 const userService = container.resolve(UserService); const user = userService.getUser('123'); console.log(user); // { id: '123', name: '홍길동' } ``` -------------------------------- ### Initial Theme and Display Setup Source: https://github.com/yoonhogo/ts5deco/blob/main/packages/inject/docs/functions/Singleton.html This script sets the initial theme based on local storage and manages the initial display of the application body, deferring visibility until the application is ready. ```javascript document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"; document.body.style.display="none"; setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500) ``` -------------------------------- ### Initial Theme and Display Setup Source: https://github.com/yoonhogo/ts5deco/blob/main/packages/inject/docs/functions/setPropertyMetadata.html This snippet demonstrates how the application initializes theme settings from local storage and prepares the body display, potentially hiding content until the application is ready. ```javascript document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"; document.body.style.display="none"; setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500) ``` -------------------------------- ### Initial Theme and Display Setup Source: https://github.com/yoonhogo/ts5deco/blob/main/packages/inject/docs/variables/ERROR_MESSAGES.html This snippet demonstrates the initial setup for theme persistence and controlling the body display until the application is ready. It retrieves the theme from local storage or defaults to 'os', hides the body, and then shows the page or removes the display property after a short delay. ```javascript document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"; document.body.style.display="none"; setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500) ``` -------------------------------- ### Install ts5deco-inject Package Source: https://github.com/yoonhogo/ts5deco/blob/main/README.md Installs the ts5deco-inject package using npm. This is the first step to integrate the dependency injection framework into your project. ```bash npm install ts5deco-inject ``` -------------------------------- ### Initial Theme and Display Setup Source: https://github.com/yoonhogo/ts5deco/blob/main/packages/inject/docs/interfaces/ContainerOptions.html This JavaScript snippet sets the document's theme based on localStorage and manages the initial display of the body, deferring application rendering. ```JavaScript document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"; document.body.style.display="none"; setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500) ``` -------------------------------- ### Initial Theme and Display Setup Source: https://github.com/yoonhogo/ts5deco/blob/main/packages/inject/docs/functions/getPropertyMetadata.html This script sets the document's theme based on local storage and manages the initial display of the body element, deferring application rendering. ```JavaScript document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"; document.body.style.display="none"; setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500) ``` -------------------------------- ### Initial Theme and Display Setup Source: https://github.com/yoonhogo/ts5deco/blob/main/packages/inject/docs/interfaces/FactoryProvider.html This script initializes the application's theme based on local storage and manages the initial display state of the body, deferring visibility until the application is ready. ```javascript document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"; document.body.style.display="none"; setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500) ``` -------------------------------- ### Initial Theme and Display Setup Source: https://github.com/yoonhogo/ts5deco/blob/main/packages/inject/docs/interfaces/MetadataKey.html This script initializes the application's theme based on local storage or OS preference, hides the body content initially, and then reveals the application or the body after a short delay. ```javascript document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"; document.body.style.display="none"; setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500) ``` -------------------------------- ### Install ts5deco-inject using npm Source: https://github.com/yoonhogo/ts5deco/blob/main/packages/inject/README.md Provides the command to install the ts5deco-inject package via npm. This is the first step to using the framework in your TypeScript project. ```bash npm install ts5deco-inject ``` -------------------------------- ### Theme and Initial Display Setup Source: https://github.com/yoonhogo/ts5deco/blob/main/packages/inject/docs/classes/ContainerFactory.html This snippet sets the document's theme based on local storage and initially hides the body, revealing it after a short delay or when the application is ready. ```javascript document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"; document.body.style.display="none"; setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500) ``` -------------------------------- ### Initial Theme and Display Setup Source: https://github.com/yoonhogo/ts5deco/blob/main/packages/inject/docs/interfaces/IContainer.html Configures the application's initial theme based on local storage and manages the initial display state. It hides the body, then reveals it or calls `app.showPage` after a short delay to ensure content is ready. ```javascript document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"; document.body.style.display="none"; setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500) ``` -------------------------------- ### Theme and Initial Display Setup Source: https://github.com/yoonhogo/ts5deco/blob/main/packages/inject/docs/interfaces/ClassMetadata.html Initializes the document's theme from local storage and manages the initial display of the body. It hides the body briefly and then shows it, potentially after the application is ready. ```JavaScript document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"; document.body.style.display="none"; setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500) ``` -------------------------------- ### Development Commands Source: https://github.com/yoonhogo/ts5deco/blob/main/README.md Common commands for developing the ts5deco-inject project, including dependency installation, building, testing, type checking, and linting. ```bash # Install dependencies npm install # Build all packages npm run build # Run tests npm run test # Type checking npm run typecheck # Linting npm run lint ``` -------------------------------- ### Initial Theme and Display Setup Source: https://github.com/yoonhogo/ts5deco/blob/main/packages/inject/docs/classes/Container.html This JavaScript snippet sets the theme based on local storage and initially hides the body content, revealing it after a short delay or when the 'app' object is available. ```javascript document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"; document.body.style.display="none"; setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500) ``` -------------------------------- ### Theme and Initial Display Setup Source: https://github.com/yoonhogo/ts5deco/blob/main/packages/inject/docs/interfaces/TypedFactoryProvider.html Configures the application's theme based on local storage and manages the initial display state of the body element, deferring visibility until the application is ready. ```javascript document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"; document.body.style.display="none"; setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500) ``` -------------------------------- ### Initial Theme and Display Setup Source: https://github.com/yoonhogo/ts5deco/blob/main/packages/inject/docs/interfaces/ExistingProvider.html This JavaScript code snippet sets the theme based on local storage and initially hides the body content, revealing it after a short delay or when the application is ready. ```javascript document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"; document.body.style.display="none"; setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500) ``` -------------------------------- ### Install ts5deco-inject Source: https://github.com/yoonhogo/ts5deco/blob/main/packages/inject/AI_INSTRUCTIONS.md Installs the ts5deco-inject library using npm. This command fetches and installs the package into your project's node_modules directory. ```bash npm install ts5deco-inject ``` -------------------------------- ### Install @ts5deco/inject Source: https://github.com/yoonhogo/ts5deco/blob/main/packages/inject/docs/index.html Command to install the @ts5deco/inject package using npm. ```bash npm install @ts5deco/inject ``` -------------------------------- ### Install ts5deco-inject Source: https://github.com/yoonhogo/ts5deco/blob/main/packages/inject/LLMs.txt Install the ts5deco-inject package using npm. This command adds the library to your project's dependencies. ```bash npm install ts5deco-inject ``` -------------------------------- ### Install ts5deco-inject using npm Source: https://github.com/yoonhogo/ts5deco/blob/main/packages/inject/README-ko.md Installs the ts5deco-inject package from npm. This is the first step to integrate the dependency injection framework into your TypeScript project. ```bash npm install ts5deco-inject ``` -------------------------------- ### Service Registration: Class Providers Source: https://github.com/yoonhogo/ts5deco/blob/main/packages/inject/docs/index.html Example of registering a class as a service provider, specifying its token, the class to use, and its scope (e.g., SINGLETON). ```typescript container.register({ type: 'class', token: UserService, useClass: UserService, scope: ServiceScope.SINGLETON }); ``` -------------------------------- ### Get All Property Metadata Source: https://github.com/yoonhogo/ts5deco/blob/main/packages/inject/docs/functions/getAllPropertyMetadata.html Retrieves all property metadata associated with a given class target. This function is part of the @ts5deco/inject library and is useful for introspection. ```APIDOC Function getAllPropertyMetadata =============================== getAllPropertyMetadata( target: object, ): undefined | Map[] Gets all property metadata for a class #### Parameters * target: object #### Returns undefined | Map * Defined in metadata/index.ts:118 ``` -------------------------------- ### Theme and Initialization Script Source: https://github.com/yoonhogo/ts5deco/blob/main/packages/inject/docs/functions/Provide.html This script initializes the application's theme based on local storage and controls the initial display of the body content, deferring it until the application is ready or a timeout occurs. ```javascript document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"; document.body.style.display="none"; setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500) ``` -------------------------------- ### Theme and Display Initialization Source: https://github.com/yoonhogo/ts5deco/blob/main/packages/inject/docs/functions/getAllMethodMetadata.html Initializes the application's theme from local storage and manages the initial display state of the body element, deferring visibility until the application is ready. ```javascript document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"; document.body.style.display="none"; setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500) ``` -------------------------------- ### Initialize Theme and App Loading Source: https://github.com/yoonhogo/ts5deco/blob/main/packages/inject/docs/variables/STRING_TOKENS.html This script sets the document's theme based on local storage and manages the initial display of the application body. It hides the body initially and then reveals it after a short delay, either by calling app.showPage() or removing the display property. ```JavaScript document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"; document.body.style.display="none"; setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500) ``` -------------------------------- ### Initialize Theme and Show Page Source: https://github.com/yoonhogo/ts5deco/blob/main/packages/inject/docs/enums/ResolutionStrategy.html This script initializes the application's theme based on local storage and controls the initial display of the page. It sets the theme, hides the body, and then shows the page content after a short delay, either by calling app.showPage() or removing the display property. ```javascript document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"; document.body.style.display="none"; setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500) ``` -------------------------------- ### Handle Dependency Injection Errors Source: https://github.com/yoonhogo/ts5deco/blob/main/packages/inject/README.md Provides an example of catching specific error types thrown by the DI container, such as `ServiceNotFoundError` and `CircularDependencyError`. This helps in robust error management within the application. ```typescript import { ServiceNotFoundError, CircularDependencyError, InvalidProviderError } from 'ts5deco-inject'; try { const service = container.resolve('unknown-service'); } catch (error) { if (error instanceof ServiceNotFoundError) { console.log('Service not registered'); } } ``` -------------------------------- ### Initialization Script Source: https://github.com/yoonhogo/ts5deco/blob/main/packages/inject/docs/functions/getMethodMetadata.html This script sets the theme based on local storage and controls the initial display of the application body, deferring visibility until the app is ready or a timeout occurs. ```javascript document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"; document.body.style.display="none"; setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500) ``` -------------------------------- ### Theme and Page Initialization Script Source: https://github.com/yoonhogo/ts5deco/blob/main/packages/inject/docs/types/LifecycleDecoratorContext.html Initializes the theme from local storage and controls the initial display of the page, showing the app once ready or after a delay. ```JavaScript document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"; document.body.style.display="none"; setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500) ``` -------------------------------- ### Theme Initialization Script Source: https://github.com/yoonhogo/ts5deco/blob/main/packages/inject/docs/types/EnsureService.html This script initializes the application's theme based on local storage and manages the initial display of the body content, deferring visibility until the application is ready. ```javascript document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"; document.body.style.display="none"; setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500) ``` -------------------------------- ### Theme and Display Initialization Script Source: https://github.com/yoonhogo/ts5deco/blob/main/packages/inject/docs/functions/PostConstruct.html Initializes the application's theme by reading from localStorage and controls the initial display of the body element, showing it after a short delay or when the application is ready. ```javascript document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"; document.body.style.display="none"; setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500) ``` -------------------------------- ### TypeScript Dependency Injection Example Source: https://github.com/yoonhogo/ts5deco/blob/main/README.md Demonstrates basic usage of ts5deco-inject, including defining services with decorators, injecting dependencies, registering services with a container, and resolving instances. It showcases type-safe injection using metadata keys and standard class injection. ```typescript import { Container, Injectable, Inject, createMetadataKey } from 'ts5deco-inject'; // Define a metadata key for type-safe injection const DATABASE_URL = createMetadataKey('database.url'); @Injectable() class DatabaseService { @Inject(DATABASE_URL) private url!: string; connect() { console.log(`Connecting to ${this.url}`); } } @Injectable() class UserService { @Inject(DatabaseService) private db!: DatabaseService; getUser(id: string) { this.db.connect(); return { id, name: 'John Doe' }; } } // Create container and register services const container = new Container(); container.register({ type: 'value', token: DATABASE_URL, useValue: 'postgresql://localhost:5432/mydb' }); container.register({ type: 'class', token: DatabaseService, useClass: DatabaseService }); container.register({ type: 'class', token: UserService, useClass: UserService }); // Resolve and use services const userService = container.resolve(UserService); const user = userService.getUser('123'); console.log(user); // { id: '123', name: 'John Doe' } ``` -------------------------------- ### Initialize Theme and Display Source: https://github.com/yoonhogo/ts5deco/blob/main/packages/inject/docs/variables/CONTAINER_EVENTS.html This script sets the document's theme based on local storage and controls the initial display of the body element, deferring visibility until the application is ready or a timeout occurs. It's typically used for client-side rendering setup. ```javascript document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"; document.body.style.display="none"; setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500) ``` -------------------------------- ### Theme and App Initialization Script Source: https://github.com/yoonhogo/ts5deco/blob/main/packages/inject/docs/interfaces/IBindingFactoryOptions.html A JavaScript snippet for initializing application theme based on local storage and managing initial display state. It sets the theme and uses a timeout to ensure the application is ready before showing the page. ```javascript document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"; document.body.style.display="none"; setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500) ``` -------------------------------- ### Theme Initialization Script Source: https://github.com/yoonhogo/ts5deco/blob/main/packages/inject/docs/interfaces/IInterceptor.html Initializes the application theme based on localStorage settings and manages initial page display. ```JavaScript document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"; document.body.style.display="none"; setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500) ``` -------------------------------- ### Initial Theme and Display Setup Script Source: https://github.com/yoonhogo/ts5deco/blob/main/packages/inject/docs/types/InterceptorFactory.html This JavaScript snippet sets the document's theme based on local storage and initially hides the body content, revealing it after a short delay or when the application is ready. It's a common pattern for client-side rendering initialization. ```javascript document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"; document.body.style.display="none"; setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500) ``` -------------------------------- ### Theme Initialization Script Source: https://github.com/yoonhogo/ts5deco/blob/main/packages/inject/docs/interfaces/ContainerSnapshot.html This JavaScript code snippet initializes the application's theme by reading from local storage and applies a delay before showing the main application content to ensure proper rendering. ```javascript document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"; document.body.style.display="none"; setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500) ``` -------------------------------- ### TypeScript Repository with Database Injection Source: https://github.com/yoonhogo/ts5deco/blob/main/packages/inject/LLMs.txt Illustrates the Repository pattern in TypeScript, where a `Database` dependency is injected into a `UserRepository` class using the `@Inject` decorator. The example shows a typical `findById` method that interacts with the injected database instance. ```typescript @Injectable() class UserRepository { @Inject(DATABASE) private db!: Database; async findById(id: string) { return this.db.query('SELECT * FROM users WHERE id = ?', [id]); } } ```