{"id":22059241,"url":"https://github.com/opentable/injecorator","last_synced_at":"2025-03-23T17:13:21.799Z","repository":{"id":57273973,"uuid":"56291620","full_name":"opentable/injecorator","owner":"opentable","description":"A simple decorator based dependecy injection framework for nodejs es6 projects","archived":false,"fork":false,"pushed_at":"2016-06-09T04:46:49.000Z","size":16,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":23,"default_branch":"master","last_synced_at":"2025-03-04T00:08:34.327Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/opentable.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-04-15T04:45:07.000Z","updated_at":"2017-03-23T13:31:35.000Z","dependencies_parsed_at":"2022-09-17T05:11:14.484Z","dependency_job_id":null,"html_url":"https://github.com/opentable/injecorator","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opentable%2Finjecorator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opentable%2Finjecorator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opentable%2Finjecorator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opentable%2Finjecorator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/opentable","download_url":"https://codeload.github.com/opentable/injecorator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245136405,"owners_count":20566588,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-30T17:27:42.129Z","updated_at":"2025-03-23T17:13:21.769Z","avatar_url":"https://github.com/opentable.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Injecorator\n===================\n\nA simple decorator based dependecy injection framework for nodejs es6 projects\n\n[![NPM version](https://badge.fury.io/js/injecorator.png)](http://badge.fury.io/js/injecorator)\n[![Build Status](https://travis-ci.org/opentable/injecorator.png?branch=master)](https://travis-ci.org/injecorator/spur-ioc)\n\n## Installation\n\n```bash\n$ npm install injecorator --save\n```\n\n## Usage\n\nusage requiring [babel-plugin-transform-decorators-legacy](https://github.com/loganfsmyth/babel-plugin-transform-decorators-legacy)  with babel 6\n\n```javascript\nimport {Inject, IocContainer } from 'injecorator';\n\nconst staticObject = { staticdep: true };\n\n@Inject(staticObject)\nclass One\n{\n    constructor(staticOb){\n        this.static = staticOb;\n        this.isReallyOne = true;\n    }\n}\n\n@Inject(staticObject, One)\nclass Two\n{\n    constructor(staticOb, oneCls){\n        this.static = staticOb;\n        this.one = oneCls;\n        this.isReallyTwo = true;\n    }    \n}\n\nconst ioc = new IocContainer();\nioc.regAll(staticObject, One, Two);\nconst two = ioc.get(Two);\nconsole.log(two);\n```\n\nWithout using javascript decorators set a static property $inject on the object that contains an array of dependencies\n```javascript\nclass Three\n{\n    constructor(two){\n        this.two = two;\n        this.isReallyThree = true;\n    }     \n}\nThree.$inject = [Two];\n```\n\nRegistering an extension or replacement dependency\n```javascript\nconst ioc = new IocContainer();\nioc.regAll(staticObject, Two);\nioc.register(One, { isReallyOne: false });\nconst two = ioc.get(Two);\nexpect(two.one.isReallyOne).to.be.equal(false);\n```\n\nRegistering a factory method as a value provider. The argument passed to this method is an instance of the ioc container\n```javascript\nclass OneDerived extends One\n{\n    constructor(staticOb){\n        super(staticOb);\n        this.isDerivedOne = true;\n    }\n}\n\nconst ioc = new IocContainer();\nioc.register(OneDerived);\nioc.register(One, (iocArg) =\u003e iocArg.get(OneDerived));\n\nconst one = ioc.get(One);\nexpect(one.isReallyOne \u0026\u0026 one.isDerivedOne).to.be.equal(true);\n```\n \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopentable%2Finjecorator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopentable%2Finjecorator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopentable%2Finjecorator/lists"}