@nestjs/common#DynamicModule TypeScript Examples
The following examples show how to use
@nestjs/common#DynamicModule.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: firebase-admin-core.module.ts From nestjs-firebase-admin with MIT License | 6 votes |
static forRoot(options: FirebaseAdminModuleOptions): DynamicModule {
const firebaseAdminModuleOptions = {
provide: FIREBASE_ADMIN_MODULE_OPTIONS,
useValue: options,
};
const app = admin.apps.length === 0 ? admin.initializeApp(options) : admin.apps[0];
const providers = this.createProviders(app);
return {
module: FirebaseAdminCoreModule,
providers: [firebaseAdminModuleOptions, ...providers],
exports: [...EXPORTS],
};
}
Example #2
Source File: gcloud-storage-core.module.ts From nestjs-gcloud-storage with MIT License | 6 votes |
static withConfig(options: GCloudStorageOptions): DynamicModule {
const gcsModuleOptions = {
provide: GCLOUD_STORAGE_MODULE_OPTIONS,
useValue: options,
};
const gcsServiceProvider = {
provide: GCloudStorageService,
useFactory: (options: GCloudStorageOptions) => new GCloudStorageService(options),
inject: [GCLOUD_STORAGE_MODULE_OPTIONS],
};
return {
module: GCloudStorageCoreModule,
providers: [gcsModuleOptions, GCloudMulterStorageService, gcsServiceProvider],
exports: [...EXPORTS],
};
}
Example #3
Source File: consul.module.ts From nestjs-consul with MIT License | 6 votes |
static forRoot<T>(config: IConsulConfig<T>): DynamicModule {
const consulServiceProvider: Provider = {
provide: ConsulService,
useFactory: async () => {
const consulService = new ConsulService<T>(config, new HttpService());
if (config.keys) {
await consulService.update();
}
return consulService;
},
};
return {
module: ConsulModule,
providers: [consulServiceProvider],
exports: [consulServiceProvider],
};
}
Example #4
Source File: fcm.module.ts From nestjs-fcm with MIT License | 6 votes |
static forRoot(options: FcmOptions): DynamicModule {
const optionsProvider: ValueProvider = {
provide: FCM_OPTIONS,
useValue: options,
};
const logger = options.logger ? options.logger : new Logger('FcmService');
return {
module: FcmModule,
providers: [
{ provide: Logger, useValue: logger },
FcmService,
optionsProvider,
],
exports: [FcmService],
};
}
Example #5
Source File: mercurius-gateway.module.ts From nestjs-mercurius with MIT License | 6 votes |
static forRoot(options: MercuriusGatewayModuleOptions): DynamicModule {
return {
module: MercuriusGatewayModule,
providers: [
{
provide: GRAPHQL_GATEWAY_MODULE_OPTIONS,
useValue: options,
},
],
};
}
Example #6
Source File: get-test-mysql.module.ts From nestjs-api-example with MIT License | 6 votes |
/**
* 테스트 MySQL ê°€ì ¸ì˜¤ê¸°
*
* @returns {DynamicModule}
*/
export function getTestMysqlModule(): DynamicModule {
return TypeOrmModule.forRoot({
type: 'mysql',
host: 'localhost',
port: 3306,
username: 'test',
password: 'test',
database: 'test',
entities: ['src/api/**/*.entity.ts'],
synchronize: true,
});
}
Example #7
Source File: typegraphql-federation.module.ts From typegraphql-nestjs with MIT License | 6 votes |
static forFeature(
options: TypeGraphQLFeatureFedarationModuleOptions = {},
): DynamicModule {
const token = `${TYPEGRAPHQL_FEATURE_FEDERATION_MODULE_OPTIONS}_${this
.forFeatureIndex++}`;
return {
module: TypeGraphQLFederationModule,
providers: [{ provide: token, useValue: options }],
exports: [token],
};
}
Example #8
Source File: cqrs-event-store.module.ts From nestjs-geteventstore with MIT License | 6 votes |
static register(
eventStoreConfig: EventStoreConnectionConfig,
eventStoreSubsystems: IEventStoreSubsystems = {
onConnectionFail: (e) => console.log('e : ', e),
},
eventBusConfig: EventBusConfigType = {},
): DynamicModule {
return {
module: CqrsEventStoreModule,
imports: [
EventStoreModule.register(eventStoreConfig, eventStoreSubsystems),
],
providers: [
{ provide: READ_EVENT_BUS_CONFIG, useValue: eventBusConfig.read },
{
provide: WRITE_EVENT_BUS_CONFIG,
useValue: { ...getDefaultEventBusConfiguration, ...eventBusConfig },
},
],
exports: [EventStoreModule],
};
}
Example #9
Source File: admin.module.ts From adminjs-nestjs with MIT License | 6 votes |
/**
* Creates admin in a synchronous way
*
* @param {AdminModuleOptions} options
* @memberof module:@adminjs/nestjs~AdminModule
* @method
* @name createAdmin
* @example
* import { Module } from '@nestjs/common';
* import { AdminModule } from '@adminjs/nestjs';
*
* \@Module({
* imports: [
* AdminModule.createAdmin({
* rootPath: '/admin',
* resources: [],
* }),
* ],
* })
* export class AppModule {}
*
*/
// This is needed by JSDoc which cannot parse this statement
public static createAdmin(options: AdminModuleOptions & CustomLoader): DynamicModule {
return {
module: AdminModule,
providers: [
{
provide: CONFIG_TOKEN,
useValue: options,
},
options.customLoader ? {
provide: AbstractLoader,
useClass: options.customLoader,
} : serveStaticProvider,
],
}
}
Example #10
Source File: containerBuilder.module.ts From amplication with Apache License 2.0 | 6 votes |
static forRoot(options: ContainerBuilderModuleOptions): DynamicModule {
return {
module: ContainerBuilderModule,
providers: [
{
provide: CONTAINER_BUILDER_OPTIONS,
useValue: { ...options, providers: {} },
},
ContainerBuilderService,
],
exports: [ContainerBuilderService],
};
}
Example #11
Source File: module.ts From nestjs-keycloak-admin with MIT License | 6 votes |
public static registerAsync(options: KeycloakModuleAsyncOptions): DynamicModule {
const customOptions = this.getCustomOptions(options)
return {
module: KeycloakModule,
imports: options.imports || [],
providers: [customOptions, this.keycloakProvider],
exports: [customOptions, this.keycloakProvider],
}
}
Example #12
Source File: ApplicationModule.ts From remix-hexagonal-architecture with MIT License | 6 votes |
static register({
session,
remixHandlerPath,
}: {
session: SessionIdStorageStrategy["cookie"];
remixHandlerPath: string;
}): DynamicModule {
const MailerClass = process.env.SENDGRID_API_KEY
? SendGridMailer
: FakeMailer;
return {
module: ApplicationModule,
providers: [
{
provide: MAILER,
useClass: MailerClass,
},
{
provide: SESSION_CONFIG,
useValue: session,
},
{
provide: REMIX_HANDLER,
useValue: remixHandlerPath,
},
],
imports: [],
};
}
Example #13
Source File: http.module.ts From nestjs-http-promise with MIT License | 6 votes |
static register(config: HttpModuleOptions): DynamicModule {
return {
module: HttpModule,
providers: [
{
provide: AXIOS_INSTANCE_TOKEN,
useValue: createAxiosInstance(config),
},
{
provide: HTTP_MODULE_ID,
useValue: randomStringGenerator(),
},
],
};
}
Example #14
Source File: google-recaptcha.module.ts From google-recaptcha with MIT License | 6 votes |
static forRoot(options: GoogleRecaptchaModuleOptions): DynamicModule {
const providers: Provider[] = [
GoogleRecaptchaGuard,
GoogleRecaptchaValidator,
RecaptchaRequestResolver,
{
provide: RECAPTCHA_OPTIONS,
useValue: options,
},
];
const httpModule = this.resolveHttpModule();
const internalProviders: Provider[] = [
Reflector,
{
provide: RECAPTCHA_HTTP_SERVICE,
useFactory: (axiosInstance: axios.AxiosInstance) => new httpModule.HttpService(axiosInstance),
inject: [
RECAPTCHA_AXIOS_INSTANCE,
],
},
{
provide: RECAPTCHA_AXIOS_INSTANCE,
useFactory: () => axios.default.create(this.transformAxiosConfig(options.axiosConfig)),
},
];
return {
global: true,
module: GoogleRecaptchaModule,
imports: [
httpModule.HttpModule,
],
providers: providers.concat(internalProviders),
exports: providers,
}
}
Example #15
Source File: nestjs-form-data.module.ts From nestjs-form-data with MIT License | 6 votes |
static config(config: FormDataInterceptorConfig): DynamicModule {
return {
module: NestjsFormDataModule,
providers: [
{
provide: GLOBAL_CONFIG_INJECT_TOKEN,
useValue: checkConfig(config),
},
],
};
}
Example #16
Source File: tracing.module.ts From nestjs-jaeger-tracing with MIT License | 6 votes |
static forRoot(options: TracingModuleOptions): DynamicModule {
const providers: Provider[] = [];
TracingModule.tracerProvider = TracerProvider.getInstance(options);
TracingModule.tracer = TracingModule.tracerProvider.getTracer();
const optionsProvider: Provider<TracingModuleOptions> = {
provide: TRACING_MODULE_OPTIONS,
useValue: options,
};
const tracerProvider: Provider = {
provide: TRACER,
useValue: TracingModule.tracer,
};
const tracerProviderFactory: Provider = {
provide: TRACER_PROVIDER,
useValue: TracingModule.tracerProvider,
};
providers.push(optionsProvider);
providers.push(tracerProvider);
providers.push(tracerProviderFactory);
return {
module: TracingModule,
providers: [
...providers,
{
provide: APP_INTERCEPTOR,
useClass: TracingInterceptor,
},
],
exports: [...providers],
};
}
Example #17
Source File: seeder.module.ts From nestjs-seeder with MIT License | 6 votes |
static register(options: SeederModuleOptions): DynamicModule {
return {
module: SeederModule,
imports: options.imports || [],
providers: [
...(options.providers || []),
...options.seeders,
{
provide: SeederService,
useFactory: (...seeders: Seeder[]): SeederService => {
return new SeederService(seeders);
},
inject: options.seeders as Type<any>[],
},
],
};
}
Example #18
Source File: bull.module.ts From nestjs-bullmq with MIT License | 6 votes |
/**
* Registers a globally available configuration under a specified "configKey".
*
* @param configKey a key under which the configuration should be available
* @param sharedBullConfig shared bull configuration object
*/
static forRoot(
configKey: string,
bullConfig: Bull.QueueOptions,
): DynamicModule;
Example #19
Source File: keycloak-connect.module.ts From nest-keycloak-connect with MIT License | 6 votes |
/**
* Register the `KeycloakConnect` module.
* @param opts `keycloak.json` path in string or {@link NestKeycloakConfig} object.
* @param config {@link NestKeycloakConfig} when using `keycloak.json` path, optional
* @returns
*/
public static register(
opts: KeycloakConnectOptions,
config?: NestKeycloakConfig,
): DynamicModule {
const keycloakConnectProviders = [
createKeycloakConnectOptionProvider(opts, config),
loggerProvider,
keycloakProvider,
KeycloakMultiTenantService,
];
return {
module: KeycloakConnectModule,
providers: keycloakConnectProviders,
exports: keycloakConnectProviders,
};
}
Example #20
Source File: app.module.ts From nest-js-products-api with MIT License | 6 votes |
static foorRoot(setting: any): DynamicModule {
return {
module: AppModule,
imports: [
DomainModule,
ApplicationModule,
InfrastructureModule.foorRoot(setting),
],
};
}
Example #21
Source File: casl.module.ts From nest-casl with MIT License | 6 votes |
static forFeature<Roles extends string = string, Subjects = SubjectType, Actions extends string = DefaultActions, User extends AuthorizableUser = AuthorizableUser<Roles>>(options: OptionsForFeature<Roles, Subjects, Actions, User>): DynamicModule {
return {
module: CaslModule,
imports: [],
// exports: [AccessService],
providers: [
AccessService,
AbilityFactory,
{
provide: CASL_FEATURE_OPTIONS,
useValue: options,
},
],
};
}
Example #22
Source File: dynamoose-core.module.ts From nestjs-dynamoose with MIT License | 6 votes |
static forRoot(options: DynamooseModuleOptions = {}): DynamicModule {
const initialProvider = {
provide: DYNAMOOSE_INITIALIZATION,
useFactory: () => initialization(options),
};
return {
module: DynamooseCoreModule,
providers: [initialProvider],
exports: [initialProvider],
};
}
Example #23
Source File: mqtt.module.ts From nest-mqtt with MIT License | 6 votes |
public static forRootAsync(options: MqttModuleAsyncOptions): DynamicModule {
return {
module: MqttModule,
providers: [
...createOptionProviders(options),
createLoggerProvider(options),
createClientProvider(),
MqttExplorer,
MqttService,
],
};
}
Example #24
Source File: mikro-orm-core.module.ts From nestjs with MIT License | 6 votes |
static async forRoot(options?: MikroOrmModuleSyncOptions): Promise<DynamicModule> {
const contextName = this.setContextName(options?.contextName);
const knex = await tryRequire(() => import('@mikro-orm/knex'));
const mongo = await tryRequire(() => import('@mikro-orm/mongodb'));
return {
module: MikroOrmCoreModule,
providers: [
{ provide: MIKRO_ORM_MODULE_OPTIONS, useValue: options || {} },
createMikroOrmProvider(contextName),
createEntityManagerProvider(options?.scope, EntityManager, contextName),
...(knex ? [createEntityManagerProvider(options?.scope, knex.SqlEntityManager, contextName)] : []),
...(mongo ? [createEntityManagerProvider(options?.scope, mongo.MongoEntityManager, contextName)] : []),
],
exports: [
contextName ? getMikroORMToken(contextName) : MikroORM,
contextName ? getEntityManagerToken(contextName) : EntityManager,
...(knex ? (contextName ? [] : [knex.SqlEntityManager as any]) : []),
...(mongo ? (contextName ? [] : [mongo.MongoEntityManager as any]) : []),
],
};
}
Example #25
Source File: tracing.module.ts From nest-xray with MIT License | 6 votes |
public static forRoot(options: TracingConfig): DynamicModule {
return {
// Make TracingService available in the whole app
global: true,
module: TracingModule,
imports: [TracingCoreModule.forRoot(options)],
exports: [TracingCoreModule],
};
}
Example #26
Source File: tenancy-feature.module.ts From nestjs-tenancy with MIT License | 6 votes |
static register(models: ModelDefinition[]): DynamicModule {
const providers = createTenancyProviders(models);
return {
module: TenancyFeatureModule,
providers,
exports: providers,
};
}
Example #27
Source File: system.module.ts From relate with GNU General Public License v3.0 | 6 votes |
static register(config: ISystemModuleConfig = {}): DynamicModule {
const {defaultEnvironmentNameOrId} = config;
const systemExtensions = loadExtensionsFor(EXTENSION_TYPES.SYSTEM, defaultEnvironmentNameOrId);
return {
imports: [...systemExtensions],
module: SystemModule,
exports: [...systemExtensions],
};
}
Example #28
Source File: redis.core-module.ts From ioredis with MIT License | 6 votes |
/* forRoot */
static forRoot(options: RedisModuleOptions, connection?: string): DynamicModule {
const redisOptionsProvider: Provider = {
provide: getRedisOptionsToken(connection),
useValue: options,
};
const redisConnectionProvider: Provider = {
provide: getRedisConnectionToken(connection),
useValue: createRedisConnection(options),
};
return {
module: RedisCoreModule,
providers: [
redisOptionsProvider,
redisConnectionProvider,
],
exports: [
redisOptionsProvider,
redisConnectionProvider,
],
};
}
Example #29
Source File: pact-consumer-core.module.ts From nestjs-pact with MIT License | 6 votes |
public static register(options: PactConsumerOverallOptions): DynamicModule {
const consumerOptProvider = ProviderFactory.create(PactModuleProviders.ConsumerOptions, options.consumer);
const publisherOptProvider = ProviderFactory.create(PactModuleProviders.PublicationOptions, options.publication);
return {
module: PactConsumerCoreModule,
exports: [PactFactory, PactPublisherProvider],
providers: [consumerOptProvider, publisherOptProvider, PactProvider, PactPublisherProvider, PactFactory],
};
}