{"_id":"@mft/di","_rev":"163-a43d25a8088fd60f64ba31267ab9218b","name":"@mft/di","dist-tags":{"latest":"1.0.4"},"versions":{"1.0.0":{"name":"@mft/di","version":"1.0.0","keywords":["dependency","injection","di","container","ioc"],"author":{"name":"Momentum Financial Technology Ltd"},"_id":"@mft/di@1.0.0","maintainers":[{"name":"thomwright","email":"npm@thomwright.co.uk"}],"homepage":"https://github.com/momentumft/di","bugs":{"url":"https://github.com/momentumft/di/issues"},"ava":{"require":["./test/setup"]},"dist":{"shasum":"02bc7ecf00b3f752395a7b1046b5abb3bb23702a","tarball":"https://registry.npmjs.org/@mft/di/-/di-1.0.0.tgz","integrity":"sha512-jjvxS8iDetZ0RIaYUOlu/+VGK8jE5mnD41QFDCL6d0yjijPrduIXd31FD2qjddCpDlQd5n5oXt5TC6Cv9vtoRA==","signatures":[{"sig":"MEQCIBH4BlgNh+4Kis0+D6yhkV/7GbX9AkPKVEAKNEzY6zvRAiAK+xcaoOF3DlVBuiLY1Nu0pP736+I9wjcsHLpcla3/5g==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"src/index.js","_from":".","_shasum":"02bc7ecf00b3f752395a7b1046b5abb3bb23702a","engines":{"node":"^6.0.0"},"gitHead":"8c62115f6ef3305f3b179a6066c8a9824083d455","scripts":{"lint":"eslint src","test":"npm run test-unit && npm run lint","prepush":"npm test","test-unit":"ava --verbose src/**/__tests__/**/*.js","preversion":"npm test","test-unit-watch":"ava --verbose --watch src/**/__tests__/**/*.js"},"_npmUser":{"name":"thomwright","email":"npm@thomwright.co.uk"},"repository":{"url":"git+ssh://git@github.com/momentumft/di.git","type":"git"},"_npmVersion":"3.10.10","description":"Dependency injection","directories":{},"_nodeVersion":"6.10.2","dependencies":{},"devDependencies":{"ava":"^0.19.0","husky":"^0.13.3","sinon":"^2.1.0","eslint":"^3.9.1","@mft/eslint-config-momentumft":"^2.1.2"},"_npmOperationalInternal":{"tmp":"tmp/di-1.0.0.tgz_1494921903550_0.0230476891156286","host":"packages-18-east.internal.npmjs.com"}},"1.0.1":{"name":"@mft/di","version":"1.0.1","keywords":["dependency","injection","di","container","ioc"],"author":{"name":"Momentum Financial Technology Ltd"},"_id":"@mft/di@1.0.1","maintainers":[{"name":"leewalters-mom","email":"lee.walters@momentumft.co.uk"},{"name":"avivbeeri","email":"avbeeri@gmail.com"},{"name":"murfious","email":"steve.murphy@momentumft.co.uk"},{"name":"artiommft","email":"artiom.ciumac@momentumft.co.uk"},{"name":"tanuck","email":"tanuck@gmail.com"},{"name":"maciej.dworakowski","email":"maciej.dworakowski@momentumft.co.uk"},{"name":"tomhicks-bsf","email":"tom.hicks@momentumft.co.uk"},{"name":"thomwright","email":"npm@thomwright.co.uk"},{"name":"tomcollins","email":"tom.collins@momentumft.co.uk"},{"name":"shweta.kamaraddi","email":"shweta.kamaraddi@momentumft.co.uk"},{"name":"mft-bamboo","email":"tech+bamboonpm@bluespeckmedia.co.uk"},{"name":"marcus.kielly","email":"marcus.kielly@momentumft.co.uk"},{"name":"davidgtonge","email":"dave.tonge@moneyhub.co.uk"},{"name":"matt.sinton-hewitt","email":"matt.sinton-hewitt@momentumft.co.uk"},{"name":"ozamarripamft","email":"omar.zamarripa@momentumft.co.uk"},{"name":"stefanspita","email":"stefan.spita@momentumft.co.uk"},{"name":"jeanpaulgorman","email":"jean-paul.gorman@momentumft.co.uk"},{"name":"ab-mft","email":"aaron.burtnyk@momentumft.co.uk"},{"name":"davidxmoody","email":"david@davidxmoody.com"},{"name":"pavel-dohnal","email":"pavel.dohnal@momentumft.co.uk"}],"homepage":"https://github.com/momentumft/di","bugs":{"url":"https://github.com/momentumft/di/issues"},"ava":{"require":["./test/setup"]},"dist":{"shasum":"fb90be788bcf74aebcc69f9bb249fbb172fc8f33","tarball":"https://registry.npmjs.org/@mft/di/-/di-1.0.1.tgz","integrity":"sha512-bsRHvnS/EJwButAPBCwe3b8JvRBr6Q/TFjMeVJIrDQGXaY31S0eF6LicoF5x980ifErEsfftNKu/tEy5DsPQ6g==","signatures":[{"sig":"MEUCIEhO4hn/J7LBEYZq55AsjxUVojs55Cg6A1cwfMblpCvZAiEAz4x0WMgyWrfnFwFoZKfKKuprVnmI4V5eRHTQlY+5fqs=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"src/index.js","_from":".","_shasum":"fb90be788bcf74aebcc69f9bb249fbb172fc8f33","engines":{"node":">=6.0.0"},"gitHead":"dcd0d0e34fe2dd0bc870fc58d8ea8927ba1c9ec1","scripts":{"lint":"eslint src","test":"npm run test-unit && npm run lint","prepush":"npm test","test-unit":"ava --verbose src/**/__tests__/**/*.js","preversion":"npm test","test-unit-watch":"ava --verbose --watch src/**/__tests__/**/*.js"},"_npmUser":{"name":"thomwright","email":"npm@thomwright.co.uk"},"repository":{"url":"git+ssh://git@github.com/momentumft/di.git","type":"git"},"_npmVersion":"3.10.10","description":"Dependency injection","directories":{},"_nodeVersion":"6.10.2","dependencies":{},"devDependencies":{"ava":"^0.19.0","husky":"^0.13.3","sinon":"^2.1.0","eslint":"^3.9.1","@mft/eslint-config-momentumft":"^2.1.2"},"_npmOperationalInternal":{"tmp":"tmp/di-1.0.1.tgz_1494923972058_0.7113519215490669","host":"packages-18-east.internal.npmjs.com"}},"1.0.2":{"name":"@mft/di","version":"1.0.2","keywords":["dependency","injection","di","container","ioc"],"author":{"name":"Momentum Financial Technology Ltd"},"_id":"@mft/di@1.0.2","maintainers":[{"name":"leewalters-mom","email":"lee.walters@momentumft.co.uk"},{"name":"avivbeeri","email":"avbeeri@gmail.com"},{"name":"murfious","email":"steve.murphy@momentumft.co.uk"},{"name":"artiommft","email":"artiom.ciumac@momentumft.co.uk"},{"name":"tanuck","email":"tanuck@gmail.com"},{"name":"maciej.dworakowski","email":"maciej.dworakowski@momentumft.co.uk"},{"name":"tomhicks-bsf","email":"tom.hicks@momentumft.co.uk"},{"name":"thomwright","email":"npm@thomwright.co.uk"},{"name":"tomcollins","email":"tom.collins@momentumft.co.uk"},{"name":"shweta.kamaraddi","email":"shweta.kamaraddi@momentumft.co.uk"},{"name":"mft-bamboo","email":"tech+bamboonpm@bluespeckmedia.co.uk"},{"name":"marcus.kielly","email":"marcus.kielly@momentumft.co.uk"},{"name":"davidgtonge","email":"dave.tonge@moneyhub.co.uk"},{"name":"matt.sinton-hewitt","email":"matt.sinton-hewitt@momentumft.co.uk"},{"name":"ozamarripamft","email":"omar.zamarripa@momentumft.co.uk"},{"name":"stefanspita","email":"stefan.spita@momentumft.co.uk"},{"name":"jeanpaulgorman","email":"jean-paul.gorman@momentumft.co.uk"},{"name":"ab-mft","email":"aaron.burtnyk@momentumft.co.uk"},{"name":"davidxmoody","email":"david@davidxmoody.com"},{"name":"pavel-dohnal","email":"pavel.dohnal@momentumft.co.uk"}],"homepage":"https://github.com/momentumft/di","bugs":{"url":"https://github.com/momentumft/di/issues"},"ava":{"require":["./test/setup"]},"dist":{"shasum":"6dfaa3560b8573c5d268b18ef42ec58c01b872cc","tarball":"https://registry.npmjs.org/@mft/di/-/di-1.0.2.tgz","integrity":"sha512-PQvLOMoJSkj1aDmo5BnY3MiRfAAd+MV53ycyhGJMZtnl69b4av6Vu1CdLb7QakMyJAUEAMD/2d5SnJfNVARcAA==","signatures":[{"sig":"MEQCIHa8CdkEZn79ZAEJijDGlRHd1cmuqTK8oX+W89EL3bnuAiBVbFAe7DKwPlCj8ea6fF5MtMBiP0iXMDG97MU7nSs6Fg==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"src/index.js","_from":".","_shasum":"6dfaa3560b8573c5d268b18ef42ec58c01b872cc","engines":{"node":">=6.0.0"},"gitHead":"4391377f38717a1e8d5a07c41632d584a1ee8147","scripts":{"lint":"eslint src","test":"npm run test-unit && npm run lint","prepush":"npm test","test-unit":"ava --verbose src/**/__tests__/**/*.js","preversion":"npm test","test-unit-watch":"ava --verbose --watch src/**/__tests__/**/*.js"},"_npmUser":{"name":"thomwright","email":"npm@thomwright.co.uk"},"repository":{"url":"git+ssh://git@github.com/momentumft/di.git","type":"git"},"_npmVersion":"3.10.10","description":"Dependency injection","directories":{},"_nodeVersion":"6.10.2","dependencies":{},"devDependencies":{"ava":"^0.19.0","husky":"^0.13.3","sinon":"^2.1.0","eslint":"^3.9.1","@mft/eslint-config-momentumft":"^2.1.2"},"_npmOperationalInternal":{"tmp":"tmp/di-1.0.2.tgz_1494924359468_0.1005478803999722","host":"packages-18-east.internal.npmjs.com"}},"1.0.3":{"name":"@mft/di","version":"1.0.3","keywords":["dependency","injection","di","container","ioc"],"author":{"name":"Momentum Financial Technology Ltd"},"_id":"@mft/di@1.0.3","maintainers":[{"name":"leewalters-mom","email":"lee.walters@momentumft.co.uk"},{"name":"avivbeeri","email":"avbeeri@gmail.com"},{"name":"murfious","email":"steve.murphy@momentumft.co.uk"},{"name":"artiommft","email":"artiom.ciumac@momentumft.co.uk"},{"name":"tanuck","email":"tanuck@gmail.com"},{"name":"maciej.dworakowski","email":"maciej.dworakowski@momentumft.co.uk"},{"name":"tomhicks-bsf","email":"tom.hicks@momentumft.co.uk"},{"name":"thomwright","email":"npm@thomwright.co.uk"},{"name":"tomcollins","email":"tom.collins@momentumft.co.uk"},{"name":"shweta.kamaraddi","email":"shweta.kamaraddi@momentumft.co.uk"},{"name":"mft-bamboo","email":"tech+bamboonpm@bluespeckmedia.co.uk"},{"name":"marcus.kielly","email":"marcus.kielly@momentumft.co.uk"},{"name":"davidgtonge","email":"dave.tonge@moneyhub.co.uk"},{"name":"matt.sinton-hewitt","email":"matt.sinton-hewitt@momentumft.co.uk"},{"name":"ozamarripamft","email":"omar.zamarripa@momentumft.co.uk"},{"name":"stefanspita","email":"stefan.spita@momentumft.co.uk"},{"name":"jeanpaulgorman","email":"jean-paul.gorman@momentumft.co.uk"},{"name":"ab-mft","email":"aaron.burtnyk@momentumft.co.uk"},{"name":"davidxmoody","email":"david@davidxmoody.com"},{"name":"pavel-dohnal","email":"pavel.dohnal@momentumft.co.uk"}],"homepage":"https://github.com/momentumft/di","bugs":{"url":"https://github.com/momentumft/di/issues"},"ava":{"require":["./test/setup"]},"dist":{"shasum":"19a0fc59feb858ff6aa127b253cb2730b183ec60","tarball":"https://registry.npmjs.org/@mft/di/-/di-1.0.3.tgz","integrity":"sha512-+VKynUE4X9F2m3a8XqRE7kuwsFA3cKRlH/R8Jv6ionrpgfl/iCyqLvAM37HXdc8/ykHz8t8GkuilCJ16rG9XUg==","signatures":[{"sig":"MEUCIQC9fI1U7gKh5BDFeRVLQpZkef5UxXHFVLESI/2FwEbcRAIgQbhWzh5QCEIqjI3uG8axKggrQ0U9E+EmNjzvK0OWhDA=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"src/index.js","_from":".","_shasum":"19a0fc59feb858ff6aa127b253cb2730b183ec60","engines":{"node":">=6.0.0"},"gitHead":"bf6d4e149ce613fea16f2720ea12392396a127d2","scripts":{"lint":"eslint src","test":"npm run test-unit && npm run lint","prepush":"npm test","test-unit":"ava --verbose src/**/__tests__/**/*.js","preversion":"npm test","test-unit-watch":"ava --verbose --watch src/**/__tests__/**/*.js"},"_npmUser":{"name":"thomwright","email":"npm@thomwright.co.uk"},"repository":{"url":"git+ssh://git@github.com/momentumft/di.git","type":"git"},"_npmVersion":"3.10.10","description":"Dependency injection","directories":{},"_nodeVersion":"6.10.2","dependencies":{},"devDependencies":{"ava":"^0.19.0","husky":"^0.13.3","sinon":"^2.1.0","eslint":"^3.9.1","@mft/eslint-config-momentumft":"^2.1.2"},"_npmOperationalInternal":{"tmp":"tmp/di-1.0.3.tgz_1496390846894_0.955699754646048","host":"s3://npm-registry-packages"}},"1.0.4":{"name":"@mft/di","version":"1.0.4","keywords":["dependency","injection","di","container","ioc"],"author":{"name":"Momentum Financial Technology Ltd"},"_id":"@mft/di@1.0.4","maintainers":[{"name":"ab-mft","email":"aaron.burtnyk@momentumft.co.uk"},{"name":"alex7m","email":"alex.moreton@moneyhub.com"},{"name":"davidgtonge","email":"dave.tonge@moneyhub.co.uk"},{"name":"jspaine","email":"painejs@hotmail.com"},{"name":"maciej.dworakowski","email":"maciej.dworakowski@momentumft.co.uk"},{"name":"mft-bamboo","email":"devops+bamboo@moneyhub.com"},{"name":"ozamarripamft","email":"omar.zamarripa@moneyhub.com"},{"name":"stefanspita","email":"stefan.spita@moneyhub.com"}],"homepage":"https://github.com/momentumft/di","bugs":{"url":"https://github.com/momentumft/di/issues"},"ava":{"files":["src/**/__tests__/*.js"],"require":["./test/setup"]},"dist":{"shasum":"bef188288cdf83388735a7f6fda476559daab895","tarball":"https://registry.npmjs.org/@mft/di/-/di-1.0.4.tgz","fileCount":17,"integrity":"sha512-ZJYni20Ly/Y2dMHWloCxWjJfzpg5DeXDdeV9xAziMEPsQk/KwbivtwjCtrszVAFLg7ClFt0mscAdNeEhToDpXg==","signatures":[{"sig":"MEUCIH7+EsmfemeL/vWOdZqTq7HRBA1uHjr8FLddWONuoBiYAiEA/QB9V1scyM/BASp82HssQUB2bTnyp09LSUe70llyqkA=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":33442,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdDIkMCRA9TVsSAnZWagAAHI4P/0EWMlRG36wZJ3qurKRm\nGwAo4rpoHRo8wvpqYDp19XS+PeHvSsmsToJLO7o4DS6DbK5/XttK21SsAlK3\nbsAZNOlux/DYUbR/CswalcFH+G/ohvvX7sexJssJv9cmV51lI5BfMAcM94Vz\nWEqpfgt32sGKFIP6EB5awr8nkqr9X3FarN2ehvO9DDkoVr+cw2rz01OC+Pq9\nB8wdH4bfqiGqCRZjN8o2aEtiXjFiUBa+cLFPk3Uh+XY4lBH0WDHZ2TWSdxBK\nLq/gn0RBLVkEDVdqUM8i0SpdKTxoPYaVR4c0JChz5APD9bhpiwGjVfjorb5Y\nqKacavIKk+X8NlRFHMRMu4kB8tbDFor5O5xKA+oFwbzQGIUK3tHTeJBmbuzX\na1WN3Pxy9ZcB4cSUA0fK7FmQJTCpMM/sXYkFD6WBuE8Gh8IM3cdOVrtju1L+\n2rbZcAaLw5qJYMRyuRFa2gh6PK9ogTPC7Q+L+ua8sYtL4f7zQ1BaA8DsV2zB\nEKwjPZJ4k2je+VtUR6zbfyWNTEiJaXstWAzfLsE+FBRMJm+MlanIDHZ7ViKt\n+MgV7M+7hYCFV+0rj6bJLkrv8jdSJjbos3nO9epv8VVTbZrDeoxxfFmpWyVD\n3pbPWB+wsUnveDlBI1nEvBPKOD+n2lN8surAO/CWLvSQ5//Y9Y3FSMO4szuf\nXsmh\r\n=wavR\r\n-----END PGP SIGNATURE-----\r\n"},"main":"src/index.js","engines":{"node":">=6.0.0"},"gitHead":"f7d5b6958dc839f57b747d7899e3e9a1d5bfbd1b","scripts":{"lint":"eslint src","test":"npm run test-unit && npm run lint","prepush":"npm test","test-unit":"ava --verbose","preversion":"npm test","test-unit-watch":"ava --verbose --watch"},"_npmUser":{"name":"ozamarripamft","email":"omar.zamarripa@moneyhub.com"},"repository":{"url":"git+ssh://git@github.com/momentumft/di.git","type":"git"},"_npmVersion":"6.9.0","description":"Dependency injection","directories":{},"_nodeVersion":"8.12.0","dependencies":{},"_hasShrinkwrap":false,"devDependencies":{"ava":"^2.1.0","husky":"^0.13.3","sinon":"^2.1.0","eslint":"^5.16.0","@mft/eslint-config-momentumft":"^4.0.0"},"_npmOperationalInternal":{"tmp":"tmp/di_1.0.4_1561102603705_0.8330661255145082","host":"s3://npm-registry-packages"}}},"time":{"created":"2017-05-16T08:05:05.407Z","modified":"2026-08-05T11:39:31.916Z","1.0.0":"2017-05-16T08:05:05.407Z","1.0.1":"2017-05-16T08:39:33.214Z","1.0.2":"2017-05-16T08:46:00.672Z","1.0.3":"2017-06-02T08:07:27.960Z","1.0.4":"2019-06-21T07:36:43.832Z"},"bugs":{"url":"https://github.com/momentumft/di/issues"},"author":{"name":"Momentum Financial Technology Ltd"},"homepage":"https://github.com/momentumft/di","keywords":["dependency","injection","di","container","ioc"],"repository":{"url":"git+ssh://git@github.com/momentumft/di.git","type":"git"},"description":"Dependency injection","maintainers":[{"email":"omar.zamarripa@moneyhub.com","name":"ozamarripamft"},{"email":"dave.tonge@moneyhub.co.uk","name":"davidgtonge"},{"email":"maciej.dworakowski@moneyhub.com","name":"maciej.dworakowski"},{"email":"hannah.goodridge@moneyhub.com","name":"hannah_goodridge"},{"email":"painejs@hotmail.com","name":"jspaine"},{"email":"shweta.kamaraddi@moneyhub.com","name":"skamaraddi"},{"email":"stefan.spita@moneyhub.com","name":"stefanspita"},{"email":"samy.bounouar@moneyhub.com","name":"samybounouar42"},{"email":"conrad.jackson@moneyhub.com","name":"conradjackson"},{"email":"jonathan.bride@moneyhub.com","name":"jon_bride_mh"},{"email":"gilbert.holland-lloyd@moneyhub.com","name":"gilbert.holland-lloyd"},{"email":"daniel.cook@moneyhub.com","name":"daniel_cook"},{"email":"jack.scott@moneyhub.com","name":"jackscott10"},{"email":"colin.adams@moneyhub.com","name":"moneyhubcolin"},{"email":"john.dyer@moneyhub.com","name":"littlejohnd"},{"email":"vicki.edwards@moneyhub.com","name":"vicki_tamar"},{"email":"phong.vu@moneyhub.com","name":"phongvu"},{"email":"chris.wood@moneyhub.com","name":"chrisw00d"},{"email":"jennifer.beckingham@moneyhub.com","name":"jenniferbeckingham"},{"email":"tom.copestake@moneyhub.com","name":"tomcopestake"},{"email":"olatunde.phoster@moneyhub.com","name":"tundeph_mh"},{"email":"matt.cobley@moneyhub.com","name":"mattcobleymh"},{"email":"piyush.goyal@moneyhub.com","name":"piyushgoyal"},{"email":"james.allen@moneyhub.com","name":"james-mh"},{"email":"paulina.cisek@moneyhub.com","name":"paulina.cisek"},{"email":"thomas.kupai@moneyhub.com","name":"thomaskupai"},{"email":"Yevhen.Sydorov@moneyhub.com","name":"yevhen.sydorov"},{"email":"nadia.pavelin@moneyhub.com","name":"nadia.pavelin"},{"email":"ingrid.acero@moneyhub.com","name":"ingrid.acero"},{"email":"lily.page@moneyhub.com","name":"lily.page"},{"email":"gareth.williams@moneyhub.com","name":"gareth.williams1"},{"email":"jake.fenley@moneyhub.com","name":"jake.fenley.moneyhub"},{"email":"tetiana.starkiv@moneyhub.com","name":"tetianastarkiv"},{"email":"allan.calderwood@moneyhub.com","name":"allan.calderwood"},{"email":"andrew.foote@moneyhub.com","name":"andrewfoote"},{"email":"fergus.morrow@moneyhub.com","name":"mh-fergus"},{"email":"richard.green@moneyhub.com","name":"richardjgreen-mh"},{"email":"ignacio.contreras@moneyhub.com","name":"ignacio.contreras"}],"readme":"# DI\n\n[![npm](https://img.shields.io/npm/v/@mft/di.svg?maxAge=1000)](https://www.npmjs.com/package/@mft/di)\n[![dependency Status](https://img.shields.io/david/momentumft/di.svg?maxAge=1000)](https://david-dm.org/momentumft/di)\n[![devDependency Status](https://img.shields.io/david/dev/momentumft/di.svg?maxAge=1000)](https://david-dm.org/momentumft/di)\n[![license](https://img.shields.io/github/license/momentumft/di.svg)](https://github.com/momentumft/di)\n[![node](https://img.shields.io/node/v/@mft/di.svg?maxAge=1000)](https://www.npmjs.com/package/@mft/di)\n\nSimple, predictable dependency injection\n\n## Example\n\n```js\nfunction myDependencyFactory() {\n  return {\n    doTheThing() {\n      return \"done\"\n    }\n  }\n}\nfunction myServiceFactory({myDependency}) {\n  return {\n    doAThing() {\n      return myDependency.doTheThing()\n    },\n  }\n}\n\nconst container = require(\"@mft/di\").createContainer(\"application\")\ncontainer.registerFactory(\"myService\", myServiceFactory)\ncontainer.registerFactory(\"myDependency\", myDependencyFactory)\n\nconst myService = container.resolve(\"myService\")\nmyService.doAThing() // \"done\"\n```\n\n## Terminology\n\n- **component** - a reusable piece of your application\n- **factory** - a function which creates a component\n- **registration** - the process of mapping an ID to a component factory\n- **resolution** - the process of mapping an ID to component instance\n- **resolver** - object which performs resolution\n- **container** - object which contains component registrations and instances, performs resolution\n- **lifetime** - how long a component instance is expected to live\n- **scope** - which components, and instances, are available to inject into a component instance\n\n## Concepts\n\nThe purpose of this library is to enable easy creation of your application's components, without having to worry about those components' dependencies.\n\n### Components\n\nComponents are the individual pieces of your application. They can be functions, objects, classes, strings... whatever you want.\n\nAn example of a component with two dependencies. Here, we have a factory function, which takes an object with named dependencies, and returns an instance of the component (in this case, an object).\n\nNotice that there is no direct dependency on the DI library here. The only requirement is that factory functions take their dependencies as named arguments (an object). This makes the code portable, easy to test, and possible to wire together manually.\n\n```js\n// my-component.js\nconst factory = ({dep1, dep2}) => {\n  const instance = {\n    get() {\n      return dep1.getSomething() + dep2.getSomethingElse()\n    },\n  }\n  return instance\n}\n```\n\n### Registration and resolution\n\nWhen we have enough components in our application, and the dependency tree starts to get deeper (e.g. `A` depends on `B` which depends on `C` etc.), wiring these components together can become tedious.\n\nWhat we can do instead is register all our component factories with a 'container', and let it be responsible for creating our components (and their dependencies) for us.\n\nHere is how we would register the component factories for the above example, and manually resolve (create) an instance of the component, with its dependencies injected.\n\n```js\nconst di = require(\"@mft/di\")\n\nconst container = di.createContainer(\"application\")\n\n// register all component factories\ncontainer.register(\"myComponent\", require(\"./my-component\"))\ncontainer.register(\"dep1\", require(\"./dep1\"))\ncontainer.register(\"dep1\", require(\"./dep2\"))\n\n// resolve an instance of the component\nconst myInstance = container.resolve(\"myComponent\")\nmyInstance.get()\n```\n\nHere we've called `container.resolve()` directly to manually resolve an instance of `myComponent`. But how do `dep1` and `dep2` get resolved? Let's have a look at `myComponent` again, but slightly re-write it to illustrate what's happening.\n\n```js\n// my-component.js\nconst factory = (resolver) => {\n  const dep1 = resolver.dep1 // resolved when this property is accessed\n  const instance = {\n    get() {\n      const dep2 = resolver.dep2 // lazily resolve dep2\n      return dep1.getSomething() + dep2.getSomethingElse()\n    },\n  }\n  return instance\n}\n```\n\nHere we can see that what actually gets injected is a 'resolver' object. Accessing properties on the resolver is what triggers resolution of dependencies.\n\n### Lifetimes\n\nA lifetime is a statement about how long a container caches a reference to a component instance.\n\nThere are two lifetimes currently supported:\n\n- `TRANSIENT`\n    - no reference cached\n    - one instance per resolution\n- `REGISTRATION`\n    - reference cached in container in which the factory was registered\n    - one instance per registration container\n\n`TRANSIENT` is the default lifetime.\n\nTo explicitly set a lifetime, use the `registerFactory` function like so:\n\n```js\ncontainer.registerFactory(\"id\", factory, di.lifetimes.REGISTRATION)\n```\n\n### Child containers\n\nSometimes you don't want a component to live for the entire life of your application, but also don't want to create a new instance every time it's resolved. For example, in an HTTP server, you might want to create some components which hold some data associated with a request.\n\nFor this, we can use child containers. Create one like so:\n\n```js\nconst di = require(\"@mft/di\")\nconst express = require('express')\nconst app = express()\n\nconst container = di.createContainer(\"application\")\n\napp.get(\"/\", (req, res) => {\n  req.container = container.child(\"request\")\n  // register some components\n  // resolve and use a component\n})\n```\n\nNow, each request can register its own components and have its own instances.\n\nIt is expected that a child container will have a shorter lifetime that its parent. Here, for example, `request` container will live only as long as the request, but the `application` container will live for the lifetime of the application.\n\nWith that in mind, there are two simple rules which dictate how instances get resolved when using child containers:\n\n- *instances get resolved in the container they were registered in*\n- *a container can only resolve dependencies from itself or a parent container*\n\nThis means nothing can depend on something with a shorter lifetime. For example, no components in the `application` container could depend on a component in the `request` container. However, components in the `request` container can depend on instances from the `application` container.\n\n## API\n\n`const di = require(\"@mft/di\")`\n\n### DI\n\n- `di.createContainer(scopeName: string) -> container`\n- `di.lifetimes.TRANSIENT`\n- `di.lifetimes.REGISTRATION`\n\n### Container\n\nServices and values can be registered with a container. It is responsible for resolving an ID to an instance.\n\n- `container.registerFactory(id: string, factory: function [, lifetime]) -> container`\n- `container.registerValue(id: string, value: any) -> container`\n- `container.registerValues(values: {string: any}) -> container`\n- `container.resolve(id: string) -> componentInstance`\n- `container.child(scopeName: string) -> container`\n\n### Factory functions\n\nFactory functions are used to create the component instances.\n\n- `factory(resolver) -> componentInstance`\n\n### Resolver\n\nThe resolver gets injected into each factory function. It is a [Proxy](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Proxy) which resolves component instances on property lookup.\n\n- `resolver[id] -> componentInstance`\n\n## Further reading\n\n[Inversion of Control Containers and the Dependency Injection pattern - Martin Fowler](https://martinfowler.com/articles/injection.html)\n\n[Dependency Injection in Node.js - 2016 edition](https://medium.com/@Jeffijoe/dependency-injection-in-node-js-2016-edition-f2a88efdd427)\n","readmeFilename":"README.md"}