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


TypeScript di.GlobalProviders類代碼示例

本文整理匯總了TypeScript中@tsed/di.GlobalProviders的典型用法代碼示例。如果您正苦於以下問題:TypeScript GlobalProviders類的具體用法?TypeScript GlobalProviders怎麽用?TypeScript GlobalProviders使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了GlobalProviders類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: before

  before(() => {
    const settings = GlobalProviders.getRegistrySettings(ProviderType.CONTROLLER);

    this.locals = new Map();
    this.provider = new ControllerProvider(Test);
    this.provider.router = "router";
    settings.onInvoke!(this.provider, this.locals, []);
  });
開發者ID:Romakita,項目名稱:ts-express-decorators,代碼行數:8,代碼來源:ControllerRegistry.spec.ts

示例2: createSettingsService

function createSettingsService(injector: InjectorService) {
  const provider = GlobalProviders.get(ServerSettingsService)!;
  const settingsService = injector.invoke<ServerSettingsService>(provider.useClass);

  injector.forkProvider(ServerSettingsService, settingsService);

  return settingsService;
}
開發者ID:Romakita,項目名稱:ts-express-decorators,代碼行數:8,代碼來源:createInjector.ts

示例3: before

  before(() => {
    this.serviceStub = Sinon.stub(GlobalProviders.getRegistry(ProviderType.INTERCEPTOR), "merge");

    Interceptor()(Test);
  });
開發者ID:Romakita,項目名稱:ts-express-decorators,代碼行數:5,代碼來源:Interceptor.spec.ts

示例4:

import {Provider, ProviderType, TypedProvidersRegistry, GlobalProviders} from "@tsed/di";

/**
 * Converter Registry.
 * @type {Registry<Provider<any>, IProvider<any>>}
 */
// tslint:disable-next-line: variable-name
export const ConverterRegistry: TypedProvidersRegistry = GlobalProviders.createRegistry(ProviderType.CONVERTER, Provider, {
  injectable: true,
  buildable: true
});
/**
 * Add a new converter in the `ProviderRegistry`. This converter will be built when `InjectorService` will be loaded.
 *
 * #### Example
 *
 * ```typescript
 * import {registerConverter, InjectorService} from "@tsed/common";
 *
 * export default class MyConverter {
 *     constructor(){}
 *     serialize() {
 *         return "test";
 *     }
 * }
 *
 * registerConverter({provide: MyConverter});
 * // or
 * registerConverter(MyConverter);
 *
 * const injector = new InjectorService();
開發者ID:Romakita,項目名稱:ts-express-decorators,代碼行數:31,代碼來源:ConverterRegistries.ts

示例5:

import {Provider, ProviderType, TypedProvidersRegistry, GlobalProviders} from "@tsed/di";
import {IFilterPreHandler} from "../interfaces/IFilterPreHandler";

/**
 *
 * @type {Registry<Provider, IProvider<any>>}
 */
// tslint:disable-next-line: variable-name
export const FilterRegistry: TypedProvidersRegistry = GlobalProviders.createRegistry(ProviderType.FILTER, Provider, {
  injectable: true,
  buildable: true
});

/**
 * Add a new filter in the `ProviderRegistry`. This filter will be built when `InjectorService` will be loaded.
 *
 * #### Example
 *
 * ```typescript
 * import {registerFilter, InjectorService} from "@tsed/common";
 *
 * export default class MyFooFilter {
 *     constructor(){}
 *     transform() {
 *         return "test";
 *     }
 * }
 *
 * registerFilter({provide: MyFooService});
 * // or
 * registerFilter(MyFooService);
開發者ID:Romakita,項目名稱:ts-express-decorators,代碼行數:31,代碼來源:FilterRegistry.ts

示例6:

import {GlobalProviders, Provider, ProviderType, TypedProvidersRegistry} from "@tsed/di";

/**
 *
 * @type {Registry<Provider<any>, Provider>}
 */
// tslint:disable-next-line: variable-name
export const MiddlewareRegistry: TypedProvidersRegistry = GlobalProviders.createRegistry(ProviderType.MIDDLEWARE, Provider, {
  injectable: true,
  buildable: true
});
/**
 * Add a new middleware in the `ProviderRegistry`. This middleware will be built when `InjectorService` will be loaded.
 *
 * #### Example
 *
 * ```typescript
 * import {registerMiddleware, InjectorService} from "@tsed/common";
 *
 * export default class FooMiddleware {
 *     constructor(){}
 *     use() {
 *         return "test";
 *     }
 * }
 *
 * registerMiddleware({provide: FooMiddleware});
 * // or
 * registerMiddleware(FooMiddleware);
 *
 * const injector = new InjectorService()
開發者ID:Romakita,項目名稱:ts-express-decorators,代碼行數:31,代碼來源:MiddlewareRegistry.ts

示例7: onInvoke

import {TypedProvidersRegistry, ProviderType, GlobalProviders} from "@tsed/di";
import {ControllerProvider} from "../class/ControllerProvider";
import {ExpressRouter} from "../services/ExpressRouter";

// tslint:disable-next-line: variable-name
export const ControllerRegistry: TypedProvidersRegistry = GlobalProviders.createRegistry(ProviderType.CONTROLLER, ControllerProvider, {
  injectable: false,
  buildable: true,

  onInvoke(provider: ControllerProvider, locals, designParamTypes) {
    if (!locals.has(ExpressRouter)) {
      locals.set(ExpressRouter, provider.router);
    }
  }
});
/**
 * Add a new controller in the `ProviderRegistry`. This controller will be built when `InjectorService` will be loaded.
 *
 * #### Example
 *
 * ```typescript
 * import {registerController, InjectorService} from "@tsed/common";
 *
 * export default class MyController {
 *     constructor(){}
 *     transform() {
 *         return "test";
 *     }
 * }
 *
 * registerController({provide: MyController});
開發者ID:Romakita,項目名稱:ts-express-decorators,代碼行數:31,代碼來源:ControllerRegistry.ts

示例8:

import {Provider, ProviderType, TypedProvidersRegistry, GlobalProviders} from "@tsed/di";

/**
 *
 * @type {Registry<Provider<any>, IProvider<any>>}
 */
// tslint:disable-next-line: variable-name
export const InterceptorRegistry: TypedProvidersRegistry = GlobalProviders.createRegistry(ProviderType.INTERCEPTOR, Provider, {
  injectable: true,
  buildable: true
});
/**
 * Add a new interceptor in the `ProviderRegistry`. This interceptor will be built when `InjectorService` will be loaded.
 *
 * #### Example
 *
 * ```typescript
 * import {registerInterceptor, InjectorService} from "@tsed/common";
 *
 * export default class MyInterceptor {
 *     constructor(){}
 *     aroundInvoke() {
 *         return "test";
 *     }
 * }
 *
 * registerInterceptor({provide: MyInterceptor});
 * // or
 * registerInterceptor(MyInterceptor);
 *
 * const injector = new InjectorService()
開發者ID:Romakita,項目名稱:ts-express-decorators,代碼行數:31,代碼來源:InterceptorRegistries.ts


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