在与 Inversify 相关的实施方面需要帮助。我正在创建一个从节点扩展 EventEmitter 的类。当我尝试使用 inversify 时,它说 EventEmitter 不可注入。以下是示例代码
//界面
export interface ISubscriber {
Connect(callback: Function);
on(event: string, listener: Function): this;
emit(event: string, ...args: any[]): boolean;
}
//班级
import {EventEmitter} from 'events';
@injectable()
class Subscriber extends EventEmitter implements ISubscriber {
logProvider: SCLogging.ILogger;
public constructor(
@inject(TYPES.ILogger) logProvider: SCLogging.ILogger,
@inject(TYPES.IConfig) config: IConfig
) {
super();
//Some Implementation
}
public Connect(callback) {
//Some Implementation
}
public on(event: string, listener: Function): this {
super.on(event, listener);
return this;
}
public emit(event: string, ...args: any[]): boolean {
return super.emit(event, ...args);
}
}
export { ISubscriber, Subscriber }
//定义绑定
kernel.bind<SCLogging.ILogger>(TYPES.ILogger).to(Logger);
kernel.bind<IConfig>(TYPES.IConfig).to(Config);
kernel.bind<ISubscriber>(TYPES.ISubscriber).to(Subscriber);
我收到错误
Error: Missing required @injectable annotation in: EventEmitter.