Duplicate Interfaces
The Problem
Section titled “The Problem”export interface INotificationService { sendNotification(message: string, recipient: string): Promise<void>;}
// Multiple implementations of the same interfaceexport class EmailNotificationService implements INotificationService { async sendNotification(message: string, recipient: string) { /* ... */ }}
export class SmsNotificationService implements INotificationService { async sendNotification(message: string, recipient: string) { /* ... */ }}
export class PushNotificationService implements INotificationService { async sendNotification(message: string, recipient: string) { /* ... */ }}The Problem: When resolving INotificationService, which implementation should the container use?
Detection
Section titled “Detection”❌ 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.How to Fix
Section titled “How to Fix”Create specific interfaces:
// Base interfaceexport interface INotificationService { sendNotification(message: string, recipient: string): Promise<void>;}
// Specific interfacesexport interface IEmailNotificationService extends INotificationService {}export interface ISmsNotificationService extends INotificationService {}export interface IPushNotificationService extends INotificationService {}
// Implementationsexport class EmailNotificationService implements IEmailNotificationService { async sendNotification(message: string, recipient: string) { /* ... */ }}
export class SmsNotificationService implements ISmsNotificationService { async sendNotification(message: string, recipient: string) { /* ... */ }}
export class PushNotificationService implements IPushNotificationService { async sendNotification(message: string, recipient: string) { /* ... */ }}Usage:
import { container } from './container.gen';
// ✅ Each interface has one implementation - no ambiguity!const emailService = container.resolve('IEmailNotificationService');const smsService = container.resolve('ISmsNotificationService');const pushService = container.resolve('IPushNotificationService');