{"id":24559163,"url":"https://github.com/tiny-nestjs/auto-injectable","last_synced_at":"2025-08-19T15:09:25.636Z","repository":{"id":184824850,"uuid":"672263701","full_name":"tiny-nestjs/auto-injectable","owner":"tiny-nestjs","description":"@tiny-nestjs/auto-injectable enables seamless DI within the Nest Framework.","archived":false,"fork":false,"pushed_at":"2023-12-03T14:06:03.000Z","size":489,"stargazers_count":26,"open_issues_count":0,"forks_count":7,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-22T00:33:51.484Z","etag":null,"topics":["library","nest","nestjs","nodejs","npm","tiny-nestjs","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@tiny-nestjs/auto-injectable","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tiny-nestjs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-07-29T13:28:19.000Z","updated_at":"2025-05-19T04:45:24.000Z","dependencies_parsed_at":"2024-10-05T13:00:39.364Z","dependency_job_id":"8b31b57b-26c3-458c-ae70-ed562ecf1744","html_url":"https://github.com/tiny-nestjs/auto-injectable","commit_stats":{"total_commits":135,"total_committers":6,"mean_commits":22.5,"dds":0.1777777777777778,"last_synced_commit":"35bcb1b4c4af68fdd66bd827bb7250bd4951a186"},"previous_names":["meltingbits/nestjs-auto-injectable","tiny-nestjs/auto-injectable"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/tiny-nestjs/auto-injectable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tiny-nestjs%2Fauto-injectable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tiny-nestjs%2Fauto-injectable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tiny-nestjs%2Fauto-injectable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tiny-nestjs%2Fauto-injectable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tiny-nestjs","download_url":"https://codeload.github.com/tiny-nestjs/auto-injectable/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tiny-nestjs%2Fauto-injectable/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271173376,"owners_count":24711667,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-19T02:00:09.176Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["library","nest","nestjs","nodejs","npm","tiny-nestjs","typescript"],"created_at":"2025-01-23T06:15:04.910Z","updated_at":"2025-08-19T15:09:25.604Z","avatar_url":"https://github.com/tiny-nestjs.png","language":"TypeScript","readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://github.com/tiny-nestjs/auto-injectable/assets/81916648/6d197834-bbf4-4370-b681-952d32712716\" alt=\"tiny-nestjs\" width=\"150\" height=\"150\" /\u003e\n\u003c/p\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"https://img.shields.io/badge/npm-v0.3.1-blue\" alt=\"npm version\"\u003e\n  \u003cimg src=\"https://img.shields.io/badge/license-MIT-green\" alt=\"License\"\u003e\n\u003c/div\u003e\n\n## Description\n\n[AutoInjectable](https://github.com/tiny-nestjs/auto-injectable) is a utility library designed to simplify the usage of\ndependency injection\nin [Nest](https://github.com/nestjs/nest). It enables seamless\nhandling of automatic injection of dependencies by the framework.\nWith this library, you can inject dependencies into classes without the need for module definitions.\n\n## Features\n\n- `@ComponentScan()` enables automatic scanning and injection of classes within a module.\n- `@AutoInjectable()` allows classes to be automatically injectable for DI.\n- `@AutoController()` automatically registers controllers.\n- `@AutoAlias()` defines an alias for the @AutoInjectable() class.\n\n## Installation\n\n```bash\nnpm install @tiny-nestjs/auto-injectable\n```\n\n```bash\nyarn add @tiny-nestjs/auto-injectable\n```\n\n## Usage\n\n**1. `@ComponentScan()` basic usage**\n\n```ts\nimport { Module } from '@nestjs/common';\nimport { ComponentScan } from '@tiny-nestjs/auto-injectable';\n\n@ComponentScan()\n@Module({\n  imports: [],\n  controllers: [],\n  providers: [],\n})\nexport class AppModule {\n}\n``` \n\nBy applying the `@ComponentScan()` decorator to the `AppModule` class, Nest will automatically scan for classes and\ninject necessary dependencies.\n\n**2. `@AutoInjectable()`**\n\n```ts\nimport { AutoInjectable } from '@tiny-nestjs/auto-injectable';\n\n@AutoInjectable()\nexport class CatService {\n  // ...\n}\n```\n\nIn this case, by applying the `@AutoInjectable()` decorator to the `CatService` class, the class has become injectable,\nallowing it to be injected into other modules without the need for module definitions. (The parameter\nof `@AutoInjectable()` is the same as `@Injectable()`)\n\n**3. `@AutoController()` and dependency injection**\n\n```ts\nimport { AutoController } from '@tiny-nestjs/auto-injectable';\n\n@AutoController()\nexport class CatController {\n  constructor(private readonly catService: CatService) {\n  }\n\n  @Get('cats')\n  getCats() {\n    return this.catService.findAll();\n  }\n}\n```\n\nThe class with the `@AutoInjectable()` decorator has been successfully injected and `/cats` api can be accessed by\napplying `@AutoController()` on `CatController` service. (The parameter of `@AutoController()` is the same\nas `@Controller()`)\n\n| You can see actual [project example](https://github.com/tiny-nestjs/auto-injectable-example) here. |\n|----------------------------------------------------------------------------------------------------|\n\n\u003cbr\u003e\n\n---\n\n\u003cbr\u003e\n\n- _Below are advanced usage techniques of the library. In most cases, utilizing the methods above will suffice._\n\n\u003cbr\u003e\n\n**4. `@AutoAlias()`**\n\n```ts\nimport { AutoAlias } from '@tiny-nestjs/auto-injectable';\nimport { AutoInjectable } from '@tiny-nestjs/auto-injectable';\n\n@AutoAlias('kitty')\n@AutoInjectable()\nexport class CatService {\n  // ...\n}\n```\n\n```ts\nimport { Inject } from '@nestjs/common';\nimport { AutoController } from '@tiny-nestjs/auto-injectable';\n\n@AutoController()\nexport class CatController {\n  constructor(@Inject('kitty') private readonly catService: CatService) {\n  }\n}\n```\n\n`@AutoAlias()` is a decorator used to specify an alias. In the constructor of the `CatService` class, `@Inject('kitty')`\nis used to configure the injection of a `CatService` instance with the alias 'kitty'.\nAs the library is fully compatible with the `Nest` core, you can use `Nest`'s built-in `@Inject()` decorator.\n\n**5. Define DI scope with the `@ComponentScan()`**\n\n```ts\nimport { Module } from '@nestjs/common';\nimport { ComponentScan } from '@tiny-nestjs/auto-injectable';\n\n@ComponentScan()\n@Module({})\nexport class AnimalModule {\n}\n``` \n\nThe library recommends using `@ComponentScan()` in the AppModule. However, to enable seamless DI within the desired\nscope, you can also specify `@ComponentScan()` in other modules.\n\n**6. `@ComponentScan()` parameters**\n\n```bash\n# normal case\n- /cat\n  - cat.module.ts\n  - ...\n```\n\n```bash\n# special case\n- /animal\n  - /cat\n    - /module\n      - cat.module.ts\n    - /service\n      - cat.service.ts\n```\n\nIn most cases, the module is positioned at the top-level directory of its domain. However, in some cases, you can\nspecify the exact directory path as an array parameter, such as `@ComponentScan(['animal/cat'])`.\n\n\u003cbr\u003e\n\n## Contribution\n\nTo contribute to this library, fork the [GitHub repository](https://github.com/tiny-nestjs/auto-injectable), make your\nchanges, and create a pull request. Your\ncontributions are highly appreciated. If you find any improvements or bugs, please open an issue.\n\n## License\n\n`@tiny-nestjs/auto-injectable` is distributed under\nthe [MIT license](https://github.com/tiny-nestjs/auto-injectable/blob/main/LICENSE).","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftiny-nestjs%2Fauto-injectable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftiny-nestjs%2Fauto-injectable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftiny-nestjs%2Fauto-injectable/lists"}