{"name":"power-di","version":"0.0.5","keywords":["di","ioc","react"],"author":{"name":"zhang740"},"license":"MIT","_id":"power-di@0.0.5","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":["dist/__tests__/*.js"]},"dist":{"shasum":"3a0fef9bd79a266708dac0125d7ee2f1e34bffff","tarball":"http://registry-npm.ywwl.com/power-di/download/power-di-0.0.5.tgz","integrity":"sha512-rLHUWiiwNN/bLt+IP6OMfK2W94svKu4gZXIpTcRbJ7lW8eUn0/SjGw9nlbhn9kpX0/l56FVEM/GzCpoGS7BSgA==","signatures":[{"sig":"MEYCIQDYJD62nkMFVI7wvEmEjIn455IGDpuW9IRuSuvNGkvzVwIhAPKN8JB9J/YeshtiokaSNSjZXAG/NNlZCBYkgpmlTNOh","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"size":1523,"noattachment":false,"key":"/power-di/-/power-di-0.0.5.tgz"},"main":"index.js","_from":".","files":["utils.js","utils.d.ts","helper.js","helper.d.ts","react.js","react.d.ts"],"_shasum":"3a0fef9bd79a266708dac0125d7ee2f1e34bffff","gitHead":"cb203cfb54edc8af52e21a09107945115d7332d5","scripts":{"test":"rimraf -- dist/__tests__ && tsc && ava -v -s","build":"rimraf -- dist && tsc","report":"npm run coverage && npm run coverage:report","coverage":"nyc npm test","reinstall":"rimraf -- node_modules && npm install","clean:dist":"rimraf -- dist","prepublish":"npm run build","coverage:report":"nyc report --reporter=lcov"},"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":"<p>\r   <a href=\"https://www.npmjs.com/package/power-di\"><img src=\"https://img.shields.io/npm/v/power-di.svg\" alt=\"Version\"></a>\r   <a href=\"https://www.npmjs.com/package/power-di\"><img src=\"https://img.shields.io/npm/l/power-di.svg\" alt=\"License\"></a>\r </","directories":{},"_nodeVersion":"6.10.0","dependencies":{},"devDependencies":{"ava":"^0.18.2","nyc":"^10.1.2","react":"^15.4.2","rimraf":"^2.6.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-0.0.5.tgz_1489648206999_0.04068012232892215","host":"packages-12-west.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":1489648207307,"_cnpm_publish_time":1489648207307,"dist-tags":{"alpha":"3.0.0-alpha.0","latest":"2.4.57"}}