mirror of
https://github.com/samanhappy/mcphub.git
synced 2025-12-24 02:39:19 -05:00
feat: implement lazy loading for data service and enhance service registration (#233)
This commit is contained in:
@@ -1,10 +1,31 @@
|
||||
import { registerService, getService } from './registry.js';
|
||||
import { DataService, DataServiceImpl } from './dataService.js';
|
||||
|
||||
registerService('dataService', {
|
||||
defaultImpl: DataServiceImpl,
|
||||
});
|
||||
let initialized = false;
|
||||
let tempDataService: DataService | null = null;
|
||||
|
||||
async function initializeServices() {
|
||||
if (initialized) return;
|
||||
|
||||
await registerService('dataService', {
|
||||
defaultImpl: DataServiceImpl,
|
||||
});
|
||||
|
||||
initialized = true;
|
||||
tempDataService = null; // Clear temp service once real one is ready
|
||||
}
|
||||
|
||||
export function getDataService(): DataService {
|
||||
return getService<DataService>('dataService');
|
||||
if (initialized) {
|
||||
return getService<DataService>('dataService');
|
||||
}
|
||||
|
||||
// Return temporary service for cases where services haven't been initialized yet
|
||||
// This allows module loading to work even before server initialization
|
||||
if (!tempDataService) {
|
||||
tempDataService = new DataServiceImpl();
|
||||
}
|
||||
return tempDataService;
|
||||
}
|
||||
|
||||
export { initializeServices };
|
||||
|
||||
Reference in New Issue
Block a user