Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/vassourita/nestjs-provider-helper

Opinionated way to manage your NestJS dependency injection
https://github.com/vassourita/nestjs-provider-helper

dependency-injection dependency-inversion helper liskov-substitution-principle nest nestjs provider solid typescript

Last synced: about 2 months ago
JSON representation

Opinionated way to manage your NestJS dependency injection

Awesome Lists containing this project

README

        

# NestJS Provider Helper

This helper creates a provider structure for NestJS modules in a opinionated way, where every provider must be a implementation of a interface

The ProviderHelper class exposes static methods to create ClassProviders, FactoryProviders, ExistingProviders and ValueProviders

### Installing

```sh
npm install nestjs-provider-helper
# or
yarn add nestjs-provider-helper
```

### ClassProvider example

```ts
@Module({
controllers: [CatsController],
providers: [
ProviderHelper.createClassProvider('ICatService', CatService),
ProviderHelper.createClassProvider('ICatRepository', CatRepository),
],
})
export class CatsModule {}
```

### FactoryProvider example

```ts
@Module({
controllers: [CatsController],
providers: [
ProviderHelper.createClassProvider('ICatRepository', CatRepository),
ProviderHelper.createFactoryProvider(
'ICatService',
(ICatRepository: catRepository) => new CatService(catRepository),
['ICatRepository']
),
],
})
export class CatsModule {}
```