Duplicate Interfaces Example
Project Structure
Section titled “Project Structure”duplicate-interfaces-example/├── services/│ ├── INotificationService.ts│ ├── EmailNotificationService.ts│ ├── SmsNotificationService.ts│ └── PushNotificationService.ts├── ioc.config.json└── README.md
Interface
Section titled “Interface”export interface INotificationService { sendNotification(message: string, recipient: string): Promise<void>; getServiceName(): string;}
Email Implementation
Section titled “Email Implementation”export class EmailNotificationService implements INotificationService { async sendNotification(message: string, recipient: string): Promise<void> { console.log(`Sending EMAIL notification to ${recipient}: ${message}`); await new Promise(resolve => setTimeout(resolve, 100)); }
getServiceName(): string { return 'Email Notification Service'; }}
SMS Implementation
Section titled “SMS Implementation”export class SmsNotificationService implements INotificationService { async sendNotification(message: string, recipient: string): Promise<void> { console.log(`Sending SMS notification to ${recipient}: ${message}`); await new Promise(resolve => setTimeout(resolve, 50)); }
getServiceName(): string { return 'SMS Notification Service'; }}
Push Implementation
Section titled “Push Implementation”export class PushNotificationService implements INotificationService { async sendNotification(message: string, recipient: string): Promise<void> { console.log(`Sending PUSH notification to ${recipient}: ${message}`); await new Promise(resolve => setTimeout(resolve, 25)); }
getServiceName(): string { return 'Push Notification Service'; }}
Configuration
Section titled “Configuration”{ "source": ".", "output": "container.gen.ts", "interface": "I[A-Z].*", "exclude": [ "**/*.test.ts", "**/*.spec.ts" ], "verbose": true, "modules": { "DuplicateModule": [ "services/**" ] }}
Expected Error
Section titled “Expected Error”Error: Interface 'INotificationService' is implemented by multiple classes: - EmailNotificationService (/path/to/services/EmailNotificationService.ts) - SmsNotificationService (/path/to/services/SmsNotificationService.ts) - PushNotificationService (/path/to/services/PushNotificationService.ts)
Multiple classes implement the same interface(s): INotificationService.Each interface should only be implemented by one class for proper dependency injection.