removed deprecated code
This commit is contained in:
parent
34c6c36695
commit
ca5f09c459
10 changed files with 18 additions and 377 deletions
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
import type { Browser } from '@stock-bot/browser';
|
||||
import type { CacheProvider } from '@stock-bot/cache';
|
||||
import type { AppConfig as StockBotAppConfig } from '@stock-bot/config';
|
||||
import type { BaseAppConfig as StockBotAppConfig } from '@stock-bot/config';
|
||||
import type { IServiceContainer } from '@stock-bot/types';
|
||||
import type { Logger } from '@stock-bot/logger';
|
||||
import type { MongoDBClient } from '@stock-bot/mongodb';
|
||||
|
|
@ -42,24 +42,6 @@ export interface ServiceDefinitions {
|
|||
serviceContainer: IServiceContainer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and configure the DI container with type safety
|
||||
*/
|
||||
export function createServiceContainer(rawConfig: unknown): AwilixContainer<ServiceDefinitions> {
|
||||
// Deprecated - use the new modular structure
|
||||
const { createServiceContainer: newCreateServiceContainer } = require('./container/factory');
|
||||
return newCreateServiceContainer(rawConfig);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initialize async services after container creation
|
||||
*/
|
||||
export async function initializeServices(container: AwilixContainer): Promise<void> {
|
||||
// Deprecated - use the new modular structure
|
||||
const { initializeServices: newInitializeServices } = await import('./container/factory');
|
||||
return newInitializeServices(container as any);
|
||||
}
|
||||
|
||||
|
||||
// Export typed container
|
||||
|
|
@ -79,16 +61,4 @@ export interface ServiceContainerOptions {
|
|||
enableProxy?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create service container directly from AppConfig
|
||||
* This eliminates the need for manual config mapping in each service
|
||||
*/
|
||||
export function createServiceContainerFromConfig(
|
||||
appConfig: StockBotAppConfig,
|
||||
options: ServiceContainerOptions = {}
|
||||
): AwilixContainer<ServiceDefinitions> {
|
||||
// Deprecated - use the new modular structure
|
||||
const { createServiceContainerFromConfig: newCreateServiceContainerFromConfig } = require('./container/factory');
|
||||
return newCreateServiceContainerFromConfig(appConfig, options);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { createContainer, InjectionMode, asFunction, type AwilixContainer } from 'awilix';
|
||||
import type { AppConfig as StockBotAppConfig, UnifiedAppConfig } from '@stock-bot/config';
|
||||
import type { BaseAppConfig as StockBotAppConfig, UnifiedAppConfig } from '@stock-bot/config';
|
||||
import { appConfigSchema, type AppConfig } from '../config/schemas';
|
||||
import { toUnifiedConfig } from '@stock-bot/config';
|
||||
import {
|
||||
|
|
|
|||
|
|
@ -1,76 +1,8 @@
|
|||
import type { AwilixContainer } from 'awilix';
|
||||
import type { AppConfig as StockBotAppConfig } from '@stock-bot/config';
|
||||
import type { BaseAppConfig as StockBotAppConfig } from '@stock-bot/config';
|
||||
import { ServiceContainerBuilder } from './builder';
|
||||
import type { ServiceDefinitions, ServiceContainerOptions } from './types';
|
||||
|
||||
/**
|
||||
* Creates a service container from raw configuration
|
||||
* @deprecated Use ServiceContainerBuilder instead
|
||||
*/
|
||||
export function createServiceContainer(rawConfig: unknown): AwilixContainer<ServiceDefinitions> {
|
||||
// For backward compatibility, we need to create the container synchronously
|
||||
// This means we'll use the original implementation pattern
|
||||
const { createContainer, InjectionMode, asValue: _asValue, asFunction } = require('awilix');
|
||||
const { appConfigSchema } = require('../config/schemas');
|
||||
const config = appConfigSchema.parse(rawConfig);
|
||||
|
||||
const container = createContainer({
|
||||
injectionMode: InjectionMode.PROXY,
|
||||
strict: true,
|
||||
});
|
||||
|
||||
// Register all services synchronously
|
||||
const {
|
||||
registerCoreServices,
|
||||
registerCacheServices,
|
||||
registerDatabaseServices,
|
||||
registerApplicationServices
|
||||
} = require('../registrations');
|
||||
|
||||
registerCoreServices(container, config);
|
||||
registerCacheServices(container, config);
|
||||
registerDatabaseServices(container, config);
|
||||
registerApplicationServices(container, config);
|
||||
|
||||
// Register service container aggregate
|
||||
container.register({
|
||||
serviceContainer: asFunction((cradle: ServiceDefinitions) => ({
|
||||
logger: cradle.logger,
|
||||
cache: cradle.cache,
|
||||
proxy: cradle.proxyManager, // Map proxyManager to proxy
|
||||
browser: cradle.browser,
|
||||
queue: cradle.queueManager, // Map queueManager to queue
|
||||
mongodb: cradle.mongoClient, // Map mongoClient to mongodb
|
||||
postgres: cradle.postgresClient, // Map postgresClient to postgres
|
||||
questdb: cradle.questdbClient, // Map questdbClient to questdb
|
||||
})).singleton(),
|
||||
});
|
||||
|
||||
return container;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a service container from StockBotAppConfig
|
||||
* @deprecated Use ServiceContainerBuilder instead
|
||||
*/
|
||||
export function createServiceContainerFromConfig(
|
||||
appConfig: StockBotAppConfig,
|
||||
options: ServiceContainerOptions = {}
|
||||
): AwilixContainer<ServiceDefinitions> {
|
||||
const builder = new ServiceContainerBuilder();
|
||||
return builder
|
||||
.withConfig(appConfig)
|
||||
.withOptions({
|
||||
...options,
|
||||
skipInitialization: true, // Legacy behavior
|
||||
})
|
||||
.build()
|
||||
.then(container => container)
|
||||
.catch(error => {
|
||||
throw error;
|
||||
}) as any; // Sync interface for backward compatibility
|
||||
}
|
||||
|
||||
/**
|
||||
* Modern async factory for creating service containers
|
||||
|
|
@ -86,14 +18,3 @@ export async function createServiceContainerAsync(
|
|||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize services in an existing container
|
||||
* @deprecated Handled automatically by ServiceContainerBuilder
|
||||
*/
|
||||
export async function initializeServices(
|
||||
container: AwilixContainer<ServiceDefinitions>
|
||||
): Promise<void> {
|
||||
const { ServiceLifecycleManager } = await import('../utils/lifecycle');
|
||||
const lifecycleManager = new ServiceLifecycleManager();
|
||||
await lifecycleManager.initializeServices(container);
|
||||
}
|
||||
|
|
@ -6,11 +6,8 @@ export * from './types';
|
|||
// Re-export IServiceContainer from types for convenience
|
||||
export type { IServiceContainer } from '@stock-bot/types';
|
||||
|
||||
// Legacy exports for backward compatibility
|
||||
// Type exports from awilix-container
|
||||
export {
|
||||
createServiceContainer,
|
||||
createServiceContainerFromConfig,
|
||||
initializeServices,
|
||||
type AppConfig,
|
||||
type ServiceCradle,
|
||||
type ServiceContainer,
|
||||
|
|
@ -21,9 +18,7 @@ export {
|
|||
export * from './container/types';
|
||||
export { ServiceContainerBuilder } from './container/builder';
|
||||
export {
|
||||
createServiceContainerAsync,
|
||||
createServiceContainer as createServiceContainerNew,
|
||||
createServiceContainerFromConfig as createServiceContainerFromConfigNew
|
||||
createServiceContainerAsync
|
||||
} from './container/factory';
|
||||
|
||||
// Configuration exports
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import { Hono } from 'hono';
|
|||
import { cors } from 'hono/cors';
|
||||
import { getLogger, setLoggerConfig, shutdownLoggers, type Logger } from '@stock-bot/logger';
|
||||
import { Shutdown } from '@stock-bot/shutdown';
|
||||
import type { AppConfig as StockBotAppConfig, UnifiedAppConfig } from '@stock-bot/config';
|
||||
import type { BaseAppConfig as StockBotAppConfig, UnifiedAppConfig } from '@stock-bot/config';
|
||||
import { toUnifiedConfig } from '@stock-bot/config';
|
||||
import type { IServiceContainer } from '@stock-bot/types';
|
||||
import type { ServiceContainer } from './awilix-container';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue