@byndyusoft/nest-dynamic-module
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

nest-dynamic-module

npm@latest test workflow code style: prettier semantic-release

DynamicModule helper for NestJS

Requirements

  • Node.js v12 LTS or later
  • npm or yarn

Install

npm install @byndyusoft/nest-dynamic-module

or

yarn add @byndyusoft/nest-dynamic-module

Usage

Example usage:

import {
  DynamicModuleHelper,
  TRegisterAsyncOptions,
} from "@byndyusoft/nest-dynamic-module";
import { DynamicModule, Inject, Injectable, Module } from "@nestjs/common";

class ExampleOptionsDto {
  public readonly connectionString!: string;
}

const EXAMPLE_OPTIONS_TOKEN = Symbol("EXAMPLE_OPTIONS_TOKEN");

@Injectable()
class ExampleProvider {
  public constructor(
    @Inject(EXAMPLE_OPTIONS_TOKEN)
    options: ExampleOptionsDto,
  ) {
    console.log(options.connectionString);
  }
}

@Module({})
class ExampleModule {
  public static registerAsync(
    options?: TRegisterAsyncOptions<ExampleOptionsDto>,
  ): DynamicModule {
    return DynamicModuleHelper.registerAsync(
      {
        module: ExampleModule,
        global: true,
        providers: [ExampleProvider],
        exports: [ExampleProvider],
      },
      EXAMPLE_OPTIONS_TOKEN,
      options,
    );
  }
}

class ConfigDto {
  public readonly exampleOptions!: ExampleOptionsDto;
}

@Module({
  imports: [
    ExampleModule.registerAsync({
      inject: [ConfigDto],
      useFactory: (config: ConfigDto) => config.exampleOptions,
    }),
  ],
})
class AppModule {}

Maintainers

License

This repository is released under version 2.0 of the Apache License.

Readme

Keywords

none

Package Sidebar

Install

npm i @byndyusoft/nest-dynamic-module

Weekly Downloads

71

Version

1.0.0

License

Apache-2.0

Unpacked Size

29.5 kB

Total Files

24

Last publish

Collaborators

  • alexanderbyndyu
  • sadcitizen
  • dmitriy.litichevskiy
  • razonrus