Typescript 如何获取typedi的自定义装饰器实例
我正在使用typeDiTypescript 如何获取typedi的自定义装饰器实例,typescript,typedi,Typescript,Typedi,我正在使用typeDi //eventDispatcher.ts import { EventDispatcher as EventDispatcherClass } from "event-dispatch"; import { Container } from "typedi"; export function EventDispatcher() { return (object: any, propertyName: string, inde
//eventDispatcher.ts
import { EventDispatcher as EventDispatcherClass } from "event-dispatch";
import { Container } from "typedi";
export function EventDispatcher() {
return (object: any, propertyName: string, index?: number): void => {
const eventDispatcher = new EventDispatcherClass();
Container.registerHandler({ object, propertyName, index, value: () => eventDispatcher });
};
}
export { EventDispatcher as EventDispatcherInterface } from "event-dispatch";
然后我可以在服务中使用它,比如:
//authService.ts
import { Service } from "typedi";
import { EventDispatcher, EventDispatcherInterface } from "../decorators";
@Service()
export default class AuthService {
constructor(@EventDispatcher() public eventDispatcher: EventDispatcherInterface) {
}
}
但是如何在函数中获取EventDispatcher的实例。因为这里没有类/构造函数。
如何使用Container.get()之类的东西来获取其实例
这是和的医生