🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@tiny-nestjs/auto-injectable

Package Overview
Dependencies
Maintainers
2
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tiny-nestjs/auto-injectable

Enables seamless DI within the Nest Framework.

npmnpm
Version
0.2.1
Version published
Weekly downloads
0
Maintainers
2
Weekly downloads
 
Created
Source

tiny-nestjs

npm version License

Description

AutoInjectable is a utility library designed to simplify the usage of dependency injection in Nest. It enables seamless handling of automatic injection of dependencies by the framework. With this library, you can inject dependencies into classes without the need for module definitions.

Features

  • @ComponentScan() decorator enables automatic scanning and injection of classes within a module.
  • @AutoInjectable() decorator allows classes to be automatically injectable for DI.
  • @AutoController() decorator automatically registers controllers.

Installation

npm install @tiny-nestjs/auto-injectable

Usage

1. @ComponentScan()

import { Module } from '@nestjs/common';
import { ComponentScan } from '@tiny-nestjs/auto-injectable';

@ComponentScan()
@Module({
  imports: [],
  controllers: [],
  providers: [],
})
export class AppModule {
}

By applying the @ComponentScan() decorator to the AppModule class, Nest will automatically scan for classes and inject necessary dependencies.

2. @AutoInjectable()

import { AutoInjectable } from '@tiny-nestjs/auto-injectable';

@AutoInjectable()
export class CatService {
  // ...
}

In this case, by applying the @AutoInjectable() decorator to the CatService class, the class has become injectable, allowing it to be injected into other modules without the need for module definitions.

3. @AutoController() and dependency injection

import { AutoController } from '@tiny-nestjs/auto-injectable';

@AutoController()
export class CatController {
  constructor(private readonly catService: CatService) {
  }

  @Get('cats')
  getCats() {
    return this.catService.findAll();
  }
}

The class with the @AutoInjectable() decorator has been successfully injected and /cats api can be accessed by applying @AutoController() on CatController service.

You can see actual project example here.

Contribution

To contribute to this library, fork the GitHub repository, make your changes, and create a pull request. Your contributions are highly appreciated. If you find any improvements or bugs, please open an issue.

License

@tiny-nestjs/auto-injectable is distributed under the MIT license.

Keywords

nest

FAQs

Package last updated on 12 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts