Skip to content

Commit

Permalink
Merge pull request #447 from underfin/useExisting-provider
Browse files Browse the repository at this point in the history
docs(dependency-injection.md): add doc for `useExisting` provider
  • Loading branch information
kamilmysliwiec authored Jun 5, 2019
2 parents db32c7e + 4ecc373 commit e332035
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions content/fundamentals/dependency-injection.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,27 @@ export class ApplicationModule {}

> info **Hint** If your factory needs other providers, you have to pass their tokens inside the `inject` array. Nest will pass instances as arguments of the function in the same order.
#### Use existing

The `useExisting` allows you creating aliases for existing providers. For example, the token `AliasedLoggerService` is an alias for `LoggerService`.

```typescript
@Injectable()
class LoggerService {}

const loggerAliasProvider = {
provide: 'AliasedLoggerService',
useExisting: LoggerService
};

@Module({
providers: [LoggerService, loggerAliasProvider],
})
export class ApplicationModule {}
```

> info **Hint** The instance of `LoggerService` will be equal to the instance defined by `AliasedLoggerService` token.
#### Export custom provider

In order to export a custom provider, we can either use a token or a whole object. The following example shows a token case:
Expand Down

0 comments on commit e332035

Please sign in to comment.