src/core/injector/injector.ts
//注射器,依赖注入
export class Injector {
//加载中间件实例
public async loadInstanceOfMiddleware(
wrapper: MiddlewareWrapper,
collection: Map<string, MiddlewareWrapper>,
module: Module) {
//中间件类型
const { metatype } = wrapper;
//中间件包装器
const currentMetatype = collection.get(metatype.name);
//如果包装器中已经有实例,直接返回
if (currentMetatype.instance !== null) return;
//如果实例不存在,解析构造函数参数,最后使用参数实例创建中间件实例,说明中间件也可以依赖注入
await this.resolveConstructorParams(wrapper as any, module, null, null, (instances) => {
collection.set(metatype.name, {
instance: new metatype(...instances),
metatype,
});
});
}
//加载控制器实例
public async loadInstanceOfRoute(wrapper: I