{"name":"power-di","version":"1.0.8","keywords":["di","ts","ioc","react"],"author":{"name":"zhang740"},"license":"MIT","_id":"power-di@1.0.8","maintainers":[{"name":"zhang740","email":"zhang740@vmzclub.com"}],"homepage":"https://github.com/zhang740/power-di#readme","bugs":{"url":"https://github.com/zhang740/power-di/issues"},"ava":{"files":["__tests__/*.js"]},"dist":{"shasum":"075c9d9021ed710d4d03286070a5856942d8d8cc","tarball":"http://registry-npm.ywwl.com/power-di/download/power-di-1.0.8.tgz","integrity":"sha512-U65vtmTKf9zqLFfRTC9/Ytfw2VutkzcToNLeGxoVAF6bAP/CpoH7/HRKcCDzFbICujUhc+Q84wDYGGiz23+AcA==","signatures":[{"sig":"MEYCIQCXszODg3Huf2q7sOxFt9HoBTEmKUmoyDipjZQxmk0/oQIhAP9146gpZgbRzgA3s25FcHMA7Ig4ACG5bp6XI5bwuZ2o","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"size":9940,"noattachment":false,"key":"/power-di/-/power-di-1.0.8.tgz"},"main":"index.js","_from":".","files":["utils.js","utils.d.ts","helper.js","helper.d.ts","react.js","react.d.ts","dist"],"_shasum":"075c9d9021ed710d4d03286070a5856942d8d8cc","gitHead":"55be37f946aa14788119fdf7be07e1c765cb5ea0","scripts":{"test":"tsc && npm run build:test && ava -v -s","report":"npm run coverage && npm run coverage:report","coverage":"nyc npm test","reinstall":"rimraf -- node_modules && npm install","test:prod":"npm run build:prod && npm run build:test && ava -v -s","build:prod":"rimraf -- dist && tsc","build:test":"rimraf -- __tests__ && tsc -p tsconfig.test.json","clean:dist":"rimraf -- dist","prepublish":"npm run build:prod","coverage:report":"nyc report --reporter=lcov","coverage:upload":"cat ./coverage/lcov.info | coveralls"},"typings":"./dist/index.d.ts","_npmUser":{"name":"zhang740","email":"zhang740@vmzclub.com"},"repository":{"url":"git+https://github.com/zhang740/power-di.git","type":"git"},"_npmVersion":"3.10.10","description":"A lightweight Dependency Injection library. Using es6 and other features, remove unnecessary concepts, easy and convenient to use.","directories":{},"_nodeVersion":"6.10.0","dependencies":{},"devDependencies":{"ava":"^0.18.2","nyc":"^10.1.2","react":"^15.4.2","rimraf":"^2.6.1","tslint":"4.5.1","coveralls":"^2.12.0","typescript":"2.2.1","@types/react":"^15.0.16","react-test-renderer":"^15.4.2","@types/react-test-renderer":"^15.4.2"},"_npmOperationalInternal":{"tmp":"tmp/power-di-1.0.8.tgz_1493807302682_0.3702410578262061","host":"packages-18-east.internal.npmjs.com"},"readme":"# Power DI\n\n[![CI](https://img.shields.io/travis/zhang740/power-di.svg?style=flat-square)](https://travis-ci.org/zhang740/power-di)\n[![Coverage](https://img.shields.io/coveralls/zhang740/power-di.svg?style=flat-square)](https://coveralls.io/github/zhang740/power-di)\n[![Version](https://img.shields.io/npm/v/power-di.svg?style=flat-square)](https://www.npmjs.com/package/power-di)\n[![License](https://img.shields.io/npm/l/power-di.svg?style=flat-square)](https://github.com/zhang740/power-di/blob/master/LICENSE)\n\nA lightweight Dependency Injection library. Using es6 and other features, remove unnecessary concepts, easy and convenient to use.\n\n## Install\n```shell\nnpm i power-di --save\n```\n\n## Example\n\n### a simple example\n```ts\nimport { IocContext } from 'power-di';\n\nclass AService { }\n\n// default instance, you can also new IocContext to get a instance.\nconst context = IocContext.DefaultInstance;\ncontext.register(AService);\nconst aService = context.get(AService); // a instance of AService\n```\n\n### inject with key\n```ts\nclass AService { }\n\nconst context = IocContext.DefaultInstance;\ncontext.register(AService, 'XService'); // key need a string or class, e.g super class or whatever class.\ncontext.get('XService');\n```\n\n### use with decorators\n```ts\nconst context = new IocContext();\n\n@injectable()\nclass NRService { }\n\n@injectable()\nclass LITestService {\n  @inject()\n  public testService: NRService;\n}\n\nconst test = context.get(LITestService);\n```\n\n### collect impl or extends of some interface/base class\n```ts\nclass A { }\n\n@classInfo()\nclass B extends A { }\n\n@classInfo()\nclass C extends A { }\n\n@injectable()\nclass LITestService {\n  @imports({ type: A })\n  public testService: A[];\n}\n\nconst test = context.get(LITestService); // test.testService as A[];\n```\n\n### use in react\n```tsx\nconst context = new IocContext;\nclass NRService { }\ncontext.register(NRService);\n\nclass TestComponent extends Component<{}, {}> {\n  @inject()\n  service: NRService;\n\n  componentDidMount() {\n    t.true(this.service instanceof NRService);\n  }\n\n  render(): any {\n    return null;\n  }\n}\n\ncreate(\n  <IocProvider context={context}>\n    <TestComponent />\n  </IocProvider>\n);\n```\n\n## Class Loader\nPower DI introduced the concept of class loader. We can customize the find rule of ioc.\n\n#### [See the test case for details.](https://github.com/zhang740/power-di/tree/master/test)\n","publish_time":1493807304505,"_cnpm_publish_time":1493807304505,"dist-tags":{"alpha":"3.0.0-alpha.0","latest":"2.4.57"}}