updated di
This commit is contained in:
parent
3227388d25
commit
c5a114d544
9 changed files with 545 additions and 306 deletions
79
libs/core/di/src/service-interfaces.ts
Normal file
79
libs/core/di/src/service-interfaces.ts
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
/**
|
||||
* Service interfaces for type-safe dependency injection
|
||||
*/
|
||||
|
||||
import type { Logger } from '@stock-bot/logger';
|
||||
import type { CacheProvider } from '@stock-bot/cache';
|
||||
import type { QueueManager } from '@stock-bot/queue';
|
||||
|
||||
// Core database client interfaces
|
||||
export interface IMongoDBClient {
|
||||
collection(name: string): any;
|
||||
getDatabase(): any;
|
||||
connect(): Promise<void>;
|
||||
disconnect(): Promise<void>;
|
||||
getPoolMetrics(): any;
|
||||
warmupPool?(): Promise<void>;
|
||||
setDynamicPoolConfig?(config: any): void;
|
||||
}
|
||||
|
||||
export interface IPostgreSQLClient {
|
||||
query(sql: string, params?: any[]): Promise<any>;
|
||||
connect(): Promise<void>;
|
||||
disconnect(): Promise<void>;
|
||||
getPoolMetrics(): any;
|
||||
warmupPool?(): Promise<void>;
|
||||
setDynamicPoolConfig?(config: any): void;
|
||||
connected: boolean;
|
||||
}
|
||||
|
||||
export interface IConnectionFactory {
|
||||
createMongoDB(config: any): Promise<{ client: IMongoDBClient; [key: string]: any }>;
|
||||
createPostgreSQL(config: any): Promise<{ client: IPostgreSQLClient; [key: string]: any }>;
|
||||
createCache(config: any): Promise<{ client: CacheProvider; [key: string]: any }>;
|
||||
createQueue(config: any): Promise<{ client: QueueManager; [key: string]: any }>;
|
||||
disposeAll(): Promise<void>;
|
||||
getPool(type: string, name: string): any;
|
||||
listPools(): any[];
|
||||
}
|
||||
|
||||
// Main service interface for data ingestion
|
||||
export interface IDataIngestionServices {
|
||||
readonly mongodb: IMongoDBClient;
|
||||
readonly postgres: IPostgreSQLClient;
|
||||
readonly cache: CacheProvider;
|
||||
readonly queue: QueueManager;
|
||||
readonly logger: Logger;
|
||||
readonly connectionFactory: IConnectionFactory;
|
||||
}
|
||||
|
||||
// Operation context interface (simplified)
|
||||
export interface IOperationContext {
|
||||
readonly logger: Logger;
|
||||
readonly traceId: string;
|
||||
readonly metadata: Record<string, any>;
|
||||
readonly services: IDataIngestionServices;
|
||||
}
|
||||
|
||||
// Handler execution context
|
||||
export interface IExecutionContext {
|
||||
readonly type: 'http' | 'queue' | 'scheduled';
|
||||
readonly services: IDataIngestionServices;
|
||||
readonly metadata: Record<string, any>;
|
||||
readonly traceId?: string;
|
||||
}
|
||||
|
||||
// Service factory interface
|
||||
export interface IServiceFactory {
|
||||
create(config: any): Promise<IDataIngestionServices>;
|
||||
dispose(services: IDataIngestionServices): Promise<void>;
|
||||
}
|
||||
|
||||
// For backwards compatibility during migration
|
||||
export interface LegacyServiceContainer {
|
||||
resolve<T>(name: string): T;
|
||||
resolveAsync<T>(name: string): Promise<T>;
|
||||
register(registration: any): void;
|
||||
createScope(): any;
|
||||
dispose(): Promise<void>;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue