當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript common.InjectorService類代碼示例

本文整理匯總了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);
    })();
開發者ID:Romakita,項目名稱:ts-express-decorators,代碼行數:9,代碼來源:di.spec.ts

示例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);
    }));
開發者ID:Romakita,項目名稱:ts-express-decorators,代碼行數:14,代碼來源:CalendarsService.spec.ts

示例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");
    }));
開發者ID:Romakita,項目名稱:ts-express-decorators,代碼行數:18,代碼來源:testing-example.spec.ts

示例4: inject

 inject([InjectorService], (injectorService: InjectorService) => {
   instance = injectorService.invoke(CalendarCtrl);
 })
開發者ID:Romakita,項目名稱:ts-express-decorators,代碼行數:3,代碼來源:testing-example.spec.ts

示例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;
  }
開發者ID:Romakita,項目名稱:ts-express-decorators,代碼行數:31,代碼來源:SocketHandlersBuilder.ts


注:本文中的@tsed/common.InjectorService類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。