{"_id":"@anyversion/anydi","name":"@anyversion/anydi","dist-tags":{"latest":"1.1.6"},"versions":{"1.1.6":{"name":"@anyversion/anydi","version":"1.1.6","description":"ioc di anywhere AnyDI","main":"index.js","scripts":{"build":"rimraf ./dist && tsc -p ./src/tsconfig.json","demo":"node -r ts-swc-register ./demo/index.ts"},"author":{"name":"gityoog"},"repository":{"type":"git","url":"git+https://github.com/AnyVersion/anydi.git"},"license":"ISC","dependencies":{"reflect-metadata":"^0.2.2"},"devDependencies":{"rimraf":"^6.0.1","ts-swc-register":"^1.3.0"},"types":"./index.d.ts","gitHead":"4d12c6e520eb829c7d3024f74ff43441b1a4c78b","bugs":{"url":"https://github.com/AnyVersion/anydi/issues"},"homepage":"https://github.com/AnyVersion/anydi#readme","_id":"@anyversion/anydi@1.1.6","_nodeVersion":"16.20.2","_npmVersion":"8.19.4","dist":{"integrity":"sha512-TiPFlvC77j6vay535IAA7jgzfcUhWBpMdxILcpldS11KCcvfQpNfJHVnM0HZ8JcL+U/Z/WZoEjGHpx9Ja6Lc7Q==","shasum":"fb43183d2b492f0e81f94677227f6578d4eec8b8","tarball":"https://registry.npmjs.org/@anyversion/anydi/-/anydi-1.1.6.tgz","fileCount":20,"unpackedSize":26331,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDWqhdODn+Dhvwi5jyM9NPdZaz+bfvAg0vWmUQYc2YseQIgEoTyjRIswnmWmRkY6JHDeRJSJTJrwIHAFQhWKUpGoWY="}]},"_npmUser":{"name":"npmyoog","email":"907850084@qq.com"},"directories":{},"maintainers":[{"name":"npmyoog","email":"907850084@qq.com"},{"name":"stringke","email":"authemail@qq.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/anydi_1.1.6_1728877620418_0.6470305798707996"},"_hasShrinkwrap":false}},"time":{"created":"2024-10-14T03:47:00.350Z","1.1.6":"2024-10-14T03:47:00.617Z","modified":"2024-10-14T03:47:00.916Z"},"maintainers":[{"name":"npmyoog","email":"907850084@qq.com"},{"name":"stringke","email":"authemail@qq.com"}],"description":"ioc di anywhere AnyDI","homepage":"https://github.com/AnyVersion/anydi#readme","repository":{"type":"git","url":"git+https://github.com/AnyVersion/anydi.git"},"author":{"name":"gityoog"},"bugs":{"url":"https://github.com/AnyVersion/anydi/issues"},"license":"ISC","readme":"### AnyDI\n\n## Install\n\n```\n$ npm install anydi --save\n```\n\n## Usage\n\n```ts\nimport { Container, Destroy, Inject, Lazy, DiContainer, Service, Root, setConfig } from \"../src\"\n\nsetConfig({ defaultLazy: true })\n\n@Service()\nclass ChildValue {\n  static id = 0\n  id = ChildValue.id++\n  constructor() {\n    console.log('Child value:', this.id)\n  }\n\n  @Destroy\n  destroy() {\n    console.log('Child value destroy:', this.id)\n  }\n}\n\n@Service()\nclass Child {\n  @Lazy() value!: ChildValue\n\n  constructor() {\n    console.log('Child init')\n  }\n\n  @Destroy\n  destroy() {\n    console.log('Child destroy')\n  }\n}\n\n@Container()\n@Service()\nclass Test2 {\n  @Inject() child!: Child\n}\n\n@Service()\nclass Test3 {\n  @Inject() value!: ChildValue\n}\n\n@Root()\n@Service()\nclass Test {\n  @Inject() private test2!: Test2\n  @Inject() private test3!: Test3\n  @Inject() private value!: ChildValue\n  constructor() {\n    console.log(this.test2.child.value.id)\n    console.log(this.test3)\n    console.log(this.value.id === this.test3.value.id, this.value.id !== this.test2.child.value.id)\n  }\n\n  @Destroy\n  destroy() {\n    console.log('Test destroy')\n  }\n}\n\nconst test = new Test\ntest.destroy()\n\n// or without @Root\n\nconst test2 = new DiContainer().factory(Test) // or new DiContainer().track(() => new Test)\ntest2.destroy()\n```\n\n## changelog","readmeFilename":"README.md"}