本文整理汇总了TypeScript中@tsed/common.InjectorService类的典型用法代码示例。如果您正苦于以下问题:TypeScript InjectorService类的具体用法?TypeScript InjectorService怎么用?TypeScript InjectorService使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了InjectorService类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: inject
await inject([InjectorService], (injector: InjectorService) => {
this.locals = new Map<string | Function, any>();
const provider = injector.getProvider(ProductsCtrl)!;
const target = provider.useClass;
this.rebuildHandler = provider.scope !== ProviderScope.SINGLETON;
this.instance = injector.invoke(target, this.locals, undefined, true);
})();
示例2: before
before(inject([InjectorService], (injectorService: InjectorService) => {
this.memoryStorage = {
set: () => {
},
get: () => {
}
};
const locals = new Map<any, any>();
locals.set(MemoryStorage, this.memoryStorage);
this.calendarsService = injectorService.invoke<CalendarsService>(CalendarsService, locals);
}));
示例3: it
it("should do something", inject([InjectorService], (injector: InjectorService) => {
// create locals map
const locals = new Map<any, any>();
// replace DbService by a faker
locals.set(DbService, {
getData: () => {
return "test";
}
});
// give the locals map to the invoke method
const instance: MyCtrl = injector.invoke<MyCtrl>(MyCtrl, locals);
// and test it
expect(!!instance).to.be.true;
expect(instance.getData()).to.equals("test");
}));
示例4: inject
inject([InjectorService], (injectorService: InjectorService) => {
instance = injectorService.invoke(CalendarCtrl);
})
示例5: bindMiddleware
/**
*
* @param target
* @param scope
* @param promise
* @returns {(args: any[]) => Promise<any[]>}
*/
private bindMiddleware(target: any, scope: any, promise: Promise<any>): Promise<any> {
const provider = this.injector.getProvider(target);
if (provider) {
const instance = provider.instance;
const handlerMetadata: ISocketProviderMetadata = Store.from(instance).get("socketIO");
if (handlerMetadata.type === SocketProviderTypes.MIDDLEWARE) {
if (handlerMetadata.error) {
return promise.catch((error: any) => this.invoke(instance, handlerMetadata.handlers.use, {error, ...scope}));
}
return promise
.then(() => this.invoke(instance, handlerMetadata.handlers.use, scope))
.then((result: any) => {
if (result) {
scope.args = [].concat(result);
}
});
}
}
return promise;
}