{"id":13660688,"url":"https://github.com/ts-stack/di","last_synced_at":"2025-05-07T12:22:18.981Z","repository":{"id":45346374,"uuid":"148990141","full_name":"ts-stack/di","owner":"ts-stack","description":"Dependency injection library for TypeScript projects.","archived":false,"fork":false,"pushed_at":"2023-01-05T07:13:06.000Z","size":1066,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-04T09:40:33.616Z","etag":null,"topics":["dependency-injection","di","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ts-stack.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-09-16T11:45:02.000Z","updated_at":"2024-07-07T12:19:24.000Z","dependencies_parsed_at":"2023-02-03T17:30:57.332Z","dependency_job_id":null,"html_url":"https://github.com/ts-stack/di","commit_stats":null,"previous_names":["kostyatretyak/ts-di"],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ts-stack%2Fdi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ts-stack%2Fdi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ts-stack%2Fdi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ts-stack%2Fdi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ts-stack","download_url":"https://codeload.github.com/ts-stack/di/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252874250,"owners_count":21817789,"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","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":["dependency-injection","di","typescript"],"created_at":"2024-08-02T05:01:24.611Z","updated_at":"2025-05-07T12:22:18.945Z","avatar_url":"https://github.com/ts-stack.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"Dependency injection library for JavaScript and TypeScript. It is an extraction of the Angular's dependency injection which means that it's feature complete, fast, reliable and well tested. Also - retrieve all API documentation with example code.\n\nUp-to-date with Angular 4.4.7, but with support DI to inherited class (when the child class does not have a constructor, while the parent class has it), and with exported `makeDecorator()`, `makeParamDecorator()`, `makePropDecorator()`, `makePropTypeDecorator()`, `reflector`, `Type` (see [reflector test](test/reflector.spec.ts)).\n\n## Install\n\n```bash\nnpm i @ts-stack/di\n```\n\nAlso you need to install `reflect-metadata` module:\n\n```bash\nnpm i reflect-metadata\n```\n\nThen, in `tsconfig.json` file, for `compilerOptions` you need to set `experimentalDecorators` and `emitDecoratorMetadata` to `true`:\n\n```json\n{\n  \"compilerOptions\": {\n    // ...\n    \"experimentalDecorators\": true,\n    \"emitDecoratorMetadata\": true\n  }\n}\n```\n\n## Example usage\n\n```ts\nimport 'reflect-metadata';\nimport { ReflectiveInjector, Injectable } from '@ts-stack/di';\n\n@Injectable()\nclass UsefulService {\n}\n\n@Injectable()\nclass NeedsService {\n  constructor(public service: UsefulService) {}\n}\n\nconst injector = ReflectiveInjector.resolveAndCreate([NeedsService, UsefulService]);\nconst needsService = injector.get(NeedsService);\nexpect(needsService instanceof NeedsService).toBe(true);\nexpect(needsService.service instanceof UsefulService).toBe(true);\n```\n\nFor more examples, see the [tests for @ts-stack/di](test/reflective_injector.spec.ts).\n\n## API\n\nFor full documentation check Angular DI docs:\n- [Dependency Injection](https://v4.angular.io/guide/dependency-injection)\n- [Hierarchical Dependency Injectors](https://v4.angular.io/guide/hierarchical-dependency-injection)\n- [Dependency Injection in action](https://v4.angular.io/guide/dependency-injection-in-action)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fts-stack%2Fdi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fts-stack%2Fdi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fts-stack%2Fdi/lists"}