{"id":28684038,"url":"https://github.com/emmat-york/angular-style-injector","last_synced_at":"2026-01-12T02:17:09.306Z","repository":{"id":296557241,"uuid":"993774130","full_name":"emmat-york/angular-style-injector","owner":"emmat-york","description":null,"archived":false,"fork":false,"pushed_at":"2025-06-08T21:53:34.000Z","size":16,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"develop","last_synced_at":"2025-06-08T22:27:50.438Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/emmat-york.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-05-31T13:50:27.000Z","updated_at":"2025-06-08T21:53:37.000Z","dependencies_parsed_at":"2025-06-01T02:45:56.519Z","dependency_job_id":"3054e066-586c-47f0-88a9-432fe7d73771","html_url":"https://github.com/emmat-york/angular-style-injector","commit_stats":null,"previous_names":["emmat-york/angular-style-injector"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/emmat-york/angular-style-injector","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emmat-york%2Fangular-style-injector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emmat-york%2Fangular-style-injector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emmat-york%2Fangular-style-injector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emmat-york%2Fangular-style-injector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/emmat-york","download_url":"https://codeload.github.com/emmat-york/angular-style-injector/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emmat-york%2Fangular-style-injector/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259752049,"owners_count":22905970,"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":[],"created_at":"2025-06-14T03:01:19.824Z","updated_at":"2026-01-12T02:17:09.300Z","avatar_url":"https://github.com/emmat-york.png","language":"TypeScript","funding_links":[],"categories":["Angular-Inspired Solutions"],"sub_categories":["Wrappers"],"readme":"# Angular-Style Injector\n\nA lightweight dependency injection container inspired by Angular's Injector.\n\n## Installation\n\n```bash\nnpm install angular-style-injector\n```\n\n## Preconditions\n\nBefore you start using this package, make sure to complete the following steps:\n\n1. Import `reflect-metadata` once in your entry point `.ts` file (`main.ts` or maybe `index.ts`).\n   Also, this import must be the first import in the file:\n\n```ts\nimport 'reflect-metadata';\n```\n\n2. Add these two essential parameters to your `tsconfig.json` file:\n\n```json\n{\n  \"compilerOptions\": {\n    \"experimentalDecorators\": true,\n    \"emitDecoratorMetadata\": true\n  }\n}\n```\n\n## Usage\n\n```ts\nimport { Injector, Injectable, InjectionToken } from 'angular-style-injector';\n\n@Injectable()\nclass Child {\n  readonly description = 'Child';\n}\n\n@Injectable()\nclass Parent {\n  readonly description = 'Parent';\n\n  constructor(readonly child: Child) {}\n}\n\nconst CLASS_TOKEN = new InjectionToken\u003cParent\u003e('useClass');\nconst VALUE_TOKEN = new InjectionToken\u003cnumber[]\u003e('useValue');\nconst FACTORY_TOKEN = new InjectionToken\u003cnumber\u003e('useFactory');\nconst EXISTING_TOKEN = new InjectionToken\u003cnumber\u003e('useExisting');\n\nconst injector = Injector.create({\n  providers: [\n    { provide: VALUE_TOKEN, useValue: 10, multi: true },\n    { provide: VALUE_TOKEN, useValue: 20, multi: true },\n    { provide: EXISTING_TOKEN, useExisting: VALUE_TOKEN },\n    {\n      provide: FACTORY_TOKEN,\n      useFactory: (array: number[]) =\u003e {\n        return array.reduce((acc, num) =\u003e acc + num, 0);\n      },\n      deps: [VALUE_TOKEN],\n    },\n  ],\n  parent: Injector.create({\n    providers: [\n      Child,\n      { provide: CLASS_TOKEN, useClass: Parent },\n    ],\n    name: 'Parent injector',\n  }),\n  name: 'Origin injector',\n});\n\nconsole.log(\n  injector.get(CLASS_TOKEN), // instance of Parent class\n  injector.get(VALUE_TOKEN), // Array: [10, 20]\n  injector.get(FACTORY_TOKEN), // Number: 30\n  injector.get(EXISTING_TOKEN), // Array: [10, 20]\n);\n```\n\n### Optional Dependencies and Fallback Values\n\nYou can control how the `Injector` resolves missing dependencies using the optional `notFoundValue`\nand `InjectOptions`.\n\nUsing `notFoundValue`\n\n```ts\nconst MISSING_TOKEN = new InjectionToken('Missing');\n\nconst injector = Injector.create({\n  providers: [],\n});\n\nconsole.log(\n  injector.get(MISSING_TOKEN, 'Default Value') // \"Default Value\"\n);\n```\n\nUsing `InjectOptions`\n\nYou can provide options like `optional`, `self`, and `skipSelf` to control resolution behavior:\n\n```ts\ninterface InjectOptions {\n  optional?: boolean; // if true, returns null when token is not found\n  self?: boolean;     // if true, only checks current injector\n  skipSelf?: boolean; // if true, skips current injector and looks up the parent chain\n}\n\nconst TOKEN = new InjectionToken\u003cstring\u003e('useValue');\n\nconst parentInjector = Injector.create({\n  providers: [{ provide: TOKEN, useValue: 'from parent' }]\n});\n\nconst childInjector = Injector.create({\n  providers: [], \n  parent: parentInjector\n});\n\nconsole.log(\n  childInjector.get(TOKEN), // \"from parent\"\n  childInjector.get(TOKEN, undefined, { self: true }), // throws Error\n  childInjector.get(TOKEN, null, { optional: true })  // returns null\n);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femmat-york%2Fangular-style-injector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femmat-york%2Fangular-style-injector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femmat-york%2Fangular-style-injector/lists"}