本文整理汇总了TypeScript中@tsed/di.GlobalProviders.createRegistry方法的典型用法代码示例。如果您正苦于以下问题:TypeScript GlobalProviders.createRegistry方法的具体用法?TypeScript GlobalProviders.createRegistry怎么用?TypeScript GlobalProviders.createRegistry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@tsed/di.GlobalProviders
的用法示例。
在下文中一共展示了GlobalProviders.createRegistry方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
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();
示例2:
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);
示例3: 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});
示例4:
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()
示例5:
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()