Add moment.js as a dependency, enhance TypeScript configuration to exclude scripts, and introduce new examples for dependency injection and health checks.

This commit is contained in:
2025-10-26 09:39:46 -04:00
parent 5d9b77ef7d
commit 3429df650f
26 changed files with 868 additions and 30 deletions

View File

@@ -1,3 +1,32 @@
import {DependencyManager} from '../src';
import {ConfigurationReader, DependencyManager, JSONConfigurationLoader, Type} from '../src/di';
import type {IMessageQueue} from '../src/example/IMessageQueue';
const dependencyManager = new DependencyManager(async path => await import(path));
async function main() {
const moduleLoader = async (path: string) => await import(`../${path}.ts`);
const dependencyManager = new DependencyManager(moduleLoader);
const configurationReader = new ConfigurationReader(dependencyManager, new JSONConfigurationLoader());
await configurationReader.load('./examples/di.json');
// Instantiate all eager types
const eagerTypes = await dependencyManager.getEagerTypes();
for (const type of eagerTypes) {
await dependencyManager.instantiateType(type);
}
// Resolve the MessageQueue
const messageQueueType = new Type('src/example/IMessageQueue');
const messageQueue = await dependencyManager.instantiateType<IMessageQueue>(messageQueueType);
messageQueue.subscribe('test-topic', (message: string) => {
console.log('[MessageQueue] [Listener] Received message:', message);
});
// Use the service
await messageQueue.publish('test-topic', 'Hello, DI!');
console.log('[MessageQueue] [Publisher] Message published successfully!');
}
main().catch(console.error);