fixed up di
This commit is contained in:
parent
d63025de90
commit
8550b1de57
5 changed files with 19 additions and 56 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import { Collection, Db, MongoClient, OptionalUnlessRequiredId } from 'mongodb';
|
||||
import type { Logger } from '@stock-bot/core/logger';
|
||||
import type { DocumentBase, MongoDBClientConfig, PoolMetrics, ConnectionEvents, DynamicPoolConfig } from './types';
|
||||
|
||||
/**
|
||||
|
|
@ -12,17 +13,17 @@ export class MongoDBClient {
|
|||
private db: Db | null = null;
|
||||
private readonly config: MongoDBClientConfig;
|
||||
private defaultDatabase: string;
|
||||
private readonly logger: any;
|
||||
private readonly logger: Logger;
|
||||
private isConnected = false;
|
||||
private readonly metrics: PoolMetrics;
|
||||
private readonly events?: ConnectionEvents;
|
||||
private dynamicPoolConfig?: DynamicPoolConfig;
|
||||
private poolMonitorInterval?: Timer;
|
||||
|
||||
constructor(config: MongoDBClientConfig, logger?: any, events?: ConnectionEvents) {
|
||||
this.config = config;
|
||||
this.defaultDatabase = config.database || 'stock';
|
||||
this.logger = logger || console;
|
||||
constructor(mongoConfig: MongoDBClientConfig, logger: Logger, events?: ConnectionEvents) {
|
||||
this.config = mongoConfig;
|
||||
this.defaultDatabase = mongoConfig.database || 'stock';
|
||||
this.logger = logger;
|
||||
this.events = events;
|
||||
this.metrics = {
|
||||
totalConnections: 0,
|
||||
|
|
@ -311,7 +312,7 @@ export class MongoDBClient {
|
|||
* Get a collection (interface compatibility method)
|
||||
* This method provides compatibility with the IMongoDBClient interface
|
||||
*/
|
||||
collection(name: string, database?: string): Collection<any> {
|
||||
collection(name: string, database?: string): Collection<DocumentBase> {
|
||||
return this.getCollection(name, database);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,23 +1,5 @@
|
|||
import { MongoDBClient } from './client';
|
||||
import type { ConnectionEvents, MongoDBClientConfig } from './types';
|
||||
// This factory is no longer needed when using Awilix DI
|
||||
// The MongoDBClient is now registered directly in the DI container
|
||||
// See: libs/core/di/src/awilix-container.ts
|
||||
|
||||
/**
|
||||
* Factory function to create a MongoDB client instance
|
||||
*/
|
||||
export function createMongoDBClient(config: MongoDBClientConfig, logger?: any, events?: ConnectionEvents): MongoDBClient {
|
||||
return new MongoDBClient(config, logger, events);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and connect a MongoDB client
|
||||
*/
|
||||
export async function createAndConnectMongoDBClient(
|
||||
config: MongoDBClientConfig,
|
||||
logger?: any,
|
||||
events?: ConnectionEvents
|
||||
): Promise<MongoDBClient> {
|
||||
const client = createMongoDBClient(config, logger, events);
|
||||
this.logger = logger || console; // Fallback to console if no logger provided
|
||||
await client.connect();
|
||||
return client;
|
||||
}
|
||||
export { MongoDBClient } from './client';
|
||||
|
|
@ -25,10 +25,5 @@ export type {
|
|||
DynamicPoolConfig,
|
||||
} from './types';
|
||||
|
||||
// Factory functions
|
||||
export {
|
||||
createMongoDBClient,
|
||||
createAndConnectMongoDBClient,
|
||||
} from './factory';
|
||||
|
||||
// Singleton pattern removed - use factory functions instead
|
||||
// Note: Factory functions removed - use Awilix DI container instead
|
||||
// See: libs/core/di/src/awilix-container.ts
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue