Skip to content

Instantly share code, notes, and snippets.

@frencojobs
Created March 13, 2023 05:07
Show Gist options
  • Save frencojobs/c7fe5b6c66b4a7c348fe7b430bc436b4 to your computer and use it in GitHub Desktop.
Save frencojobs/c7fe5b6c66b4a7c348fe7b430bc436b4 to your computer and use it in GitHub Desktop.
Dropper Pattern in NestJS
import {Module, Inject, Injectable, ConfigurableModuleBuilder} from '@nestjs/common'
const {ConfigurableModuleClass, MODULE_OPTIONS_TOKEN} = new ConfigurableModuleBuilder<unknown>().build()
@Injectable()
class DropperService<T> {
constructor(@Inject(MODULE_OPTIONS_TOKEN) private readonly value: T) {}
drop(): T {
return this.value
}
}
@Module({
providers: [DropperService],
exports: [DropperService]
})
export class DropperModule extends ConfigurableModuleClass {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment