{"_id":"@elumixor/di","_rev":"7-cbc9539ed9481be618fcd3915df70784","name":"@elumixor/di","dist-tags":{"latest":"0.3.2"},"versions":{"0.0.1":{"name":"@elumixor/di","version":"0.0.1","_id":"@elumixor/di@0.0.1","maintainers":[{"name":"elumixor","email":"vladogim97@gmail.com"}],"homepage":"https://github.com/elumixor/di#readme","bugs":{"url":"https://github.com/elumixor/di/issues"},"dist":{"shasum":"e302e6a3efbb7ca769ef11cb6afe24d6f5879bd5","tarball":"https://registry.npmjs.org/@elumixor/di/-/di-0.0.1.tgz","fileCount":4,"integrity":"sha512-16s3D2GXQbUjM99Y8wjSexijmYrfsr93z+Ooi2G0927t/diZzOKZtS4vE13E4lXd12FGL59mVIawVf4d0KK8tg==","signatures":[{"sig":"MEYCIQDlKJHd02Zf3uylOP4cjIHt4utVsWFX462R3dHf2uyY0wIhAI1LHk45RwUil4xk24m/f1rrn1oIyeIg9CSrLABK6Gaj","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":992},"main":"dist/index.js","type":"module","types":"dist/index.d.ts","module":"index.ts","scripts":{"build":"bun run build:bundle && bun run build:declaration","build:bundle":"bun build ./src/index.ts --outdir ./dist","build:declaration":"tsc --emitDeclarationOnly --declaration --project tsconfig.json"},"_npmUser":{"name":"elumixor","email":"vladogim97@gmail.com"},"repository":{"url":"git+https://github.com/elumixor/di.git","type":"git"},"_npmVersion":"10.2.3","description":"Very simple and lightweight Dependency Injection library for TypeScript","directories":{},"_nodeVersion":"20.10.0","_hasShrinkwrap":false,"peerDependencies":{"typescript":"^5.0.0"},"_npmOperationalInternal":{"tmp":"tmp/di_0.0.1_1723119478717_0.7203900316945133","host":"s3://npm-registry-packages"}},"0.1.1":{"name":"@elumixor/di","version":"0.1.1","_id":"@elumixor/di@0.1.1","maintainers":[{"name":"elumixor","email":"vladogim97@gmail.com"}],"homepage":"https://github.com/elumixor/di#readme","bugs":{"url":"https://github.com/elumixor/di/issues"},"dist":{"shasum":"c0774c971078081081c4f6af8c0bec8bb3f0cc26","tarball":"https://registry.npmjs.org/@elumixor/di/-/di-0.1.1.tgz","fileCount":4,"integrity":"sha512-YvUi4YSqtJIsxdhOEIwzPxGlZ5CH8ORHdlPS4jsyqNl7q4VUVlSWyza6OEWSBjXXVo/3zZxs1xgPpDG4eGrgrg==","signatures":[{"sig":"MEYCIQDKlr7yGiBhgfkXsD6NhLqJCjjtLknavUQthKg/SR4WfgIhAJAwtxy3uWd2Z5WvSUfyo4EG3ptTzvgUhiBVEoVVHxYp","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":1296},"main":"dist/index.js","type":"module","types":"dist/index.d.ts","module":"index.ts","gitHead":"1f247143b1a0c2260209bc72a361aff8d86b5209","scripts":{"lint":"bun run eslint --ext .ts .","build":"bun run build:bundle && bun run build:declaration","build:bundle":"bun build ./src/index.ts --outdir ./dist","release:major":"npm version major -m \"Release v%s\" && git push --tags","release:minor":"npm version minor -m \"Release v%s\" && git push --tags","release:patch":"npm version patch -m \"Release v%s\" && git push --tags","build:declaration":"tsc --project tsconfig.json"},"_npmUser":{"name":"elumixor","email":"vladogim97@gmail.com"},"repository":{"url":"git+https://github.com/elumixor/di.git","type":"git"},"_npmVersion":"10.8.1","description":"Very simple and lightweight Dependency Injection library for TypeScript","directories":{},"_nodeVersion":"20.16.0","dependencies":{"@elumixor/eslint":"^0.2.0"},"_hasShrinkwrap":false,"peerDependencies":{"typescript":"^5.0.0"},"_npmOperationalInternal":{"tmp":"tmp/di_0.1.1_1723120909882_0.9010882744840782","host":"s3://npm-registry-packages"}},"0.2.0":{"name":"@elumixor/di","version":"0.2.0","_id":"@elumixor/di@0.2.0","maintainers":[{"name":"elumixor","email":"vladogim97@gmail.com"}],"homepage":"https://github.com/elumixor/di#readme","bugs":{"url":"https://github.com/elumixor/di/issues"},"dist":{"shasum":"7e3d0fba2a7f44439250ee572818882aa9eeca4a","tarball":"https://registry.npmjs.org/@elumixor/di/-/di-0.2.0.tgz","fileCount":5,"integrity":"sha512-giB5WG9wRRfUrvn6z6oF6UPWe2hfz7sDNGLrbg5cyTuurvBTefKHM2cqaM8W44ZpqjWKjyzleE3DD5BAhwac5w==","signatures":[{"sig":"MEUCIB2JHHB4bH3r8uyJXcEjrOLtZ1MgCGhmjSBp+bar4uIgAiEAqJTku9otRe7O+vBXHEP6VuHwFqPdUcgRrk1pR46gWUw=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":3962},"main":"dist/index.js","type":"module","types":"dist/index.d.ts","module":"index.ts","gitHead":"7a63e8b8c8e2de48923c1074355080f8cd3cac31","scripts":{"lint":"bun run eslint --ext .ts .","build":"bun run build:bundle && bun run build:declaration","build:bundle":"bun build ./src/index.ts --outdir ./dist","release:major":"npm version major -m \"Release v%s\" && git push --tags","release:minor":"npm version minor -m \"Release v%s\" && git push --tags","release:patch":"npm version patch -m \"Release v%s\" && git push --tags","build:declaration":"tsc --project tsconfig.json"},"_npmUser":{"name":"elumixor","email":"vladogim97@gmail.com"},"repository":{"url":"git+https://github.com/elumixor/di.git","type":"git"},"_npmVersion":"10.8.1","description":"Very simple and lightweight Dependency Injection library for TypeScript","directories":{},"_nodeVersion":"20.16.0","dependencies":{"@elumixor/eslint":"^0.2.0"},"_hasShrinkwrap":false,"peerDependencies":{"typescript":"^5.0.0"},"_npmOperationalInternal":{"tmp":"tmp/di_0.2.0_1723121953287_0.14094813516933025","host":"s3://npm-registry-packages"}},"0.2.1":{"name":"@elumixor/di","version":"0.2.1","_id":"@elumixor/di@0.2.1","maintainers":[{"name":"elumixor","email":"vladogim97@gmail.com"}],"homepage":"https://github.com/elumixor/di#readme","bugs":{"url":"https://github.com/elumixor/di/issues"},"dist":{"shasum":"45fc765ec544f71936d553bc56745453ae8a23db","tarball":"https://registry.npmjs.org/@elumixor/di/-/di-0.2.1.tgz","fileCount":5,"integrity":"sha512-CSEjag7zn28YEtuNJX7AihKS6QKrXj5EWL89cStE6a/SI4SW8XNpKZej7969nK2mX7P6g4i6SLlgYnX+Jw5dnw==","signatures":[{"sig":"MEQCIHMsGXyHSgWPFkmkyC7KkvmD4om3iBWhNB1ddsS6qSoqAiBaPLk/w0S6c59AN8EG5HaSpoxZohV07OvrKPRvSRbZ0w==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":3925},"main":"dist/index.js","types":"dist/index.d.ts","gitHead":"731c017bdce01f632aa97c63e3c4d25faff9033d","scripts":{"lint":"bun run eslint --ext .ts .","build":"bun run build:bundle && bun run build:declaration","build:bundle":"bun build ./src/index.ts --outdir ./dist","release:major":"npm version major -m \"Release v%s\" && git push --tags","release:minor":"npm version minor -m \"Release v%s\" && git push --tags","release:patch":"npm version patch -m \"Release v%s\" && git push --tags","build:declaration":"tsc --project tsconfig.json"},"_npmUser":{"name":"elumixor","email":"vladogim97@gmail.com"},"repository":{"url":"git+https://github.com/elumixor/di.git","type":"git"},"_npmVersion":"10.8.1","description":"Very simple and lightweight Dependency Injection library for TypeScript","directories":{},"_nodeVersion":"20.16.0","dependencies":{"@elumixor/eslint":"^0.2.0"},"_hasShrinkwrap":false,"peerDependencies":{"typescript":"^5.0.0"},"_npmOperationalInternal":{"tmp":"tmp/di_0.2.1_1723195244754_0.12502297947174612","host":"s3://npm-registry-packages"}},"0.2.2":{"name":"@elumixor/di","version":"0.2.2","_id":"@elumixor/di@0.2.2","maintainers":[{"name":"elumixor","email":"vladogim97@gmail.com"}],"homepage":"https://github.com/elumixor/di#readme","bugs":{"url":"https://github.com/elumixor/di/issues"},"dist":{"shasum":"ccc5406e0c1fefaf54d817ed23b9c0066e5b50ea","tarball":"https://registry.npmjs.org/@elumixor/di/-/di-0.2.2.tgz","fileCount":5,"integrity":"sha512-qPiXU2SuVbPSqGHNOw8TJ8qNOg1YRAV+9FB4lENt5xbdcEuacldeF4cBQXGM6CMMQeGrI8/pV8wY9PfaPhtNUA==","signatures":[{"sig":"MEUCIQDKc0ZwZS7tjtXXaZcHH2shFHGAndZJSqysHj/ZymUqvQIgXDB1sKPr6T4JnUq/Z3TO6WOCF6dPQ/TzX6irycZ4LEo=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":3990},"main":"dist/index.js","types":"dist/index.d.ts","gitHead":"4cd7e3814e8731e9d983b79f0c32ad7985c070e6","scripts":{"lint":"bun run eslint --ext .ts .","build":"bun run build:bundle && bun run build:declaration","build:bundle":"bun build ./src/index.ts --outdir ./dist","release:major":"npm version major -m \"Release v%s\" && git push --tags","release:minor":"npm version minor -m \"Release v%s\" && git push --tags","release:patch":"npm version patch -m \"Release v%s\" && git push --tags","build:declaration":"tsc --project tsconfig.json"},"_npmUser":{"name":"elumixor","email":"vladogim97@gmail.com"},"repository":{"url":"git+https://github.com/elumixor/di.git","type":"git"},"_npmVersion":"10.8.2","description":"Very simple and lightweight Dependency Injection library for TypeScript","directories":{},"_nodeVersion":"20.18.1","dependencies":{"@elumixor/eslint":"^0.2.0"},"_hasShrinkwrap":false,"peerDependencies":{"typescript":"^5.0.0"},"_npmOperationalInternal":{"tmp":"tmp/di_0.2.2_1734731733147_0.902356761725249","host":"s3://npm-registry-packages-npm-production"}},"0.2.4":{"name":"@elumixor/di","version":"0.2.4","_id":"@elumixor/di@0.2.4","maintainers":[{"name":"elumixor","email":"vladogim97@gmail.com"}],"homepage":"https://github.com/elumixor/di#readme","bugs":{"url":"https://github.com/elumixor/di/issues"},"dist":{"shasum":"f7f62ab01c67b021877d0f8fc9f605f8f5811787","tarball":"https://registry.npmjs.org/@elumixor/di/-/di-0.2.4.tgz","fileCount":5,"integrity":"sha512-+qA+FXdF/ioPkMLffAu617b+WDVPb5qBZ8zVax6IQZclkEhb+bfpf4DlzNJp2z+QrEjX6JdkbyIeeHFqgama8A==","signatures":[{"sig":"MEYCIQCk5TmeiUZm+DZ4rT+FTXxb0R5pOPxtq/wP2iHmDMrYjQIhAN2Oe5tNMp1QOPdpSnuJUWrmlWKKZAEn6KKLfoBXNvKa","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":3976},"main":"dist/index.js","types":"dist/index.d.ts","gitHead":"c170baf322626fc68673a61a9ea359e5209e6876","scripts":{"lint":"biome check","build":"bun run build:bundle && bun run build:declaration","build:bundle":"bun build ./src/index.ts --outdir ./dist","release:major":"npm version major -m \"Release v%s\" && git push --tags","release:minor":"npm version minor -m \"Release v%s\" && git push --tags","release:patch":"npm version patch -m \"Release v%s\" && git push --tags","build:declaration":"tsc --project tsconfig.json"},"_npmUser":{"name":"elumixor","email":"vladogim97@gmail.com"},"repository":{"url":"git+https://github.com/elumixor/di.git","type":"git"},"_npmVersion":"10.8.2","description":"Very simple and lightweight Dependency Injection library for TypeScript","directories":{},"_nodeVersion":"20.19.4","_hasShrinkwrap":false,"devDependencies":{"@types/bun":"^1.2.21","typescript":"^5.0.0","@biomejs/biome":"2.2.2"},"_npmOperationalInternal":{"tmp":"tmp/di_0.2.4_1757204997078_0.9330017067980425","host":"s3://npm-registry-packages-npm-production"}},"0.3.2":{"name":"@elumixor/di","version":"0.3.2","main":"dist/index.js","types":"dist/index.d.ts","description":"Very simple and lightweight Dependency Injection library for TypeScript","repository":{"type":"git","url":"git+https://github.com/elumixor/di.git"},"scripts":{"build":"bun run build:bundle && bun run build:declaration","build:bundle":"bun build ./src/index.ts --outdir ./dist","build:declaration":"tsc --project tsconfig.json","lint":"biome check","release:patch":"npm version patch -m \"Release v%s\" && git push --tags","release:minor":"npm version minor -m \"Release v%s\" && git push --tags","release:major":"npm version major -m \"Release v%s\" && git push --tags"},"devDependencies":{"@biomejs/biome":"2.2.2","@types/bun":"^1.2.21","typescript":"^5.0.0"},"gitHead":"b53277694968123bc933b2274fa8ca9a9d9f2c1b","_id":"@elumixor/di@0.3.2","bugs":{"url":"https://github.com/elumixor/di/issues"},"homepage":"https://github.com/elumixor/di#readme","_nodeVersion":"24.13.0","_npmVersion":"11.6.2","dist":{"integrity":"sha512-tA06Bak9bbsMibbpnJFM46pY5H1A8Boo0ySs0iIWIZVzQIJurJGuq75JUKeUur9Irpb+5GtCAmt9nOx/uUpDZA==","shasum":"bfc7b68bb45a1f431d2b066022c7998e1a48c785","tarball":"https://registry.npmjs.org/@elumixor/di/-/di-0.3.2.tgz","fileCount":5,"unpackedSize":6847,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@elumixor%2fdi@0.3.2","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDUKxBLlPB1O5U1XW4yGBAOKBKDR28nSIiEGbW4dcxcsQIhAN4ZGxCdaJGDiP2HxXNaG6/JUVQI0yCVGcyEpFzZ4opc"}]},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:f368ff66-3b71-467b-8aef-4026b10518da"}},"directories":{},"maintainers":[{"name":"elumixor","email":"vladogim97@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/di_0.3.2_1771012485625_0.40225868478040905"},"_hasShrinkwrap":false}},"time":{"created":"2024-08-08T12:17:58.640Z","modified":"2026-02-13T19:54:46.031Z","0.0.1":"2024-08-08T12:17:58.875Z","0.1.1":"2024-08-08T12:41:50.011Z","0.2.0":"2024-08-08T12:59:13.434Z","0.2.1":"2024-08-09T09:20:44.887Z","0.2.2":"2024-12-20T21:55:33.332Z","0.2.4":"2025-09-07T00:29:57.275Z","0.3.2":"2026-02-13T19:54:45.776Z"},"bugs":{"url":"https://github.com/elumixor/di/issues"},"homepage":"https://github.com/elumixor/di#readme","repository":{"type":"git","url":"git+https://github.com/elumixor/di.git"},"description":"Very simple and lightweight Dependency Injection library for TypeScript","maintainers":[{"name":"elumixor","email":"vladogim97@gmail.com"}],"readme":"# @elumixor/di\n\n[![Build](https://github.com/elumixor/di/actions/workflows/build.yml/badge.svg)](https://github.com/elumixor/di/actions/workflows/build.yml)\n[![Latest NPM version](https://img.shields.io/npm/v/@elumixor/di.svg)](https://www.npmjs.com/package/@elumixor/di)\n\nMinimal dependency injection for TypeScript. ~76 lines, zero dependencies, singleton-scoped global container.\n\n## Installation\n\n```bash\nnpm install @elumixor/di\n```\n\n## Quick Start\n\n```typescript\nimport { di } from \"@elumixor/di\";\n\n// 1. Mark a class as injectable\nconst UserService = di.injectable(\n  class UserService {\n    getUser(id: string) {\n      return { id, name: \"Alice\" };\n    }\n  },\n);\n\n// 2. Instantiate it (automatically registered in the container)\nnew UserService();\n\n// 3. Retrieve it anywhere\nconst userService = di.inject(UserService);\nuserService.getUser(\"1\"); // { id: \"1\", name: \"Alice\" }\n```\n\n## API\n\nAll functions are accessed via the `di` namespace object.\n\n### `di.injectable(Class)`\n\nWraps a class so that instantiating it automatically registers the instance in the global container.\n\n```typescript\nconst Logger = di.injectable(\n  class Logger {\n    log(msg: string) {\n      console.log(msg);\n    }\n  },\n);\n\nnew Logger(); // registered automatically\n```\n\nEach injectable class is a singleton — constructing it a second time throws an error.\n\n### `di.inject(Class, options?)`\n\nRetrieves a registered instance from the container.\n\n```typescript\nconst logger = di.inject(Logger); // throws if not registered\n```\n\nPass `{ optional: true }` to return `undefined` instead of throwing:\n\n```typescript\nconst logger = di.inject(Logger, { optional: true }); // Logger | undefined\n```\n\n### `di.provide(Class, instance)`\n\nManually registers an instance. Useful for classes you don't control or for providing mock implementations in tests.\n\n```typescript\nclass ExternalApi {\n  fetch(url: string) {\n    /* ... */\n  }\n}\n\nconst api = new ExternalApi();\ndi.provide(ExternalApi, api);\n\n// later\ndi.inject(ExternalApi); // returns api\n```\n\nThrows if the class is already registered.\n\n### `di.uninject(Class)`\n\nRemoves a class from the container. Useful for cleanup in tests.\n\n```typescript\ndi.uninject(Logger);\n// Logger can now be re-registered\n```\n\n## Patterns\n\n### Abstract base class as a token\n\nYou can register against an abstract class, allowing consumers to depend on an abstraction:\n\n```typescript\nabstract class Database {\n  abstract query(sql: string): unknown;\n}\n\nclass PostgresDatabase extends Database {\n  query(sql: string) {\n    /* ... */\n  }\n}\n\ndi.provide(Database, new PostgresDatabase());\n\n// Consumers only know about Database\nconst db = di.inject(Database);\n```\n\n### Testing with mocks\n\n```typescript\n// Reset and provide a mock before each test\ndi.uninject(UserService);\ndi.provide(UserService, { getUser: () => ({ id: \"1\", name: \"Mock\" }) } as any);\n```\n\n## Design\n\n- **Singleton scope** — one instance per class, stored in a global `Map` on `globalThis`\n- **Class constructors as tokens** — no string keys, no symbols, no interfaces\n- **No auto-wiring** — dependencies are resolved explicitly via `di.inject()`\n- **No decorators** — `di.injectable()` is a plain function wrapper, no decorator metadata required\n","readmeFilename":"README.md"}