Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript 如何获取typedi的自定义装饰器实例_Typescript_Typedi - Fatal编程技术网

Typescript 如何获取typedi的自定义装饰器实例

Typescript 如何获取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

我正在使用typeDi

//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()之类的东西来获取其实例

这是和的医生