{"id":19680993,"url":"https://github.com/zixiaowang/di","last_synced_at":"2025-08-16T11:10:21.395Z","repository":{"id":132695398,"uuid":"117081475","full_name":"ZixiaoWang/di","owner":"ZixiaoWang","description":"Dependency Injection Module","archived":false,"fork":false,"pushed_at":"2018-05-24T10:34:15.000Z","size":86,"stargazers_count":18,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-29T04:43:14.891Z","etag":null,"topics":["dependency-injection","javasript","metadata","typescript"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/ZixiaoWang.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-01-11T09:50:53.000Z","updated_at":"2023-09-21T09:36:41.000Z","dependencies_parsed_at":null,"dependency_job_id":"8c393709-eb8c-44b5-a92d-f66c22a3329f","html_url":"https://github.com/ZixiaoWang/di","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ZixiaoWang/di","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZixiaoWang%2Fdi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZixiaoWang%2Fdi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZixiaoWang%2Fdi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZixiaoWang%2Fdi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ZixiaoWang","download_url":"https://codeload.github.com/ZixiaoWang/di/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZixiaoWang%2Fdi/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270702562,"owners_count":24630877,"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","status":"online","status_checked_at":"2025-08-16T02:00:11.002Z","response_time":91,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["dependency-injection","javasript","metadata","typescript"],"created_at":"2024-11-11T18:06:41.088Z","updated_at":"2025-08-16T11:10:21.387Z","avatar_url":"https://github.com/ZixiaoWang.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DI Module \u003csmall\u003ev2\u003c/small\u003e\nDependency Injection Module  \nThe module was inspired by di.js in @angular.\n\n### Quick Navigate\n1. Decorator  \n    * [Injectable](#Injectable)\n    * [Inject](#Inject)\n    * [Component](#Component)\n2. Global Variables\n    * [INJECTABLE_STORE](#INJECTABLE_STORE)\n    * [INSTANCE_STORE](#INSTANCE_STORE)\n    * [COMPONENT_STORE](#COMPONENT_STORE)\n3. Functions\n    * [boostrap](#bootstrap)\n    * [construct](#construct)\n    * [instanize](#instanize)\n4. Interface\n    * [componentConfig](#componentConfig) (reference only)\n    * [providerConfig](#providerConfig) (reference only)\n4. [Examples](#Examples)\n5. [Lisence](#Lisence)\n\n### Cookbook\n#### Injectable\nUse ```@Injectable()``` decorator to register class to ```INJECTABLE_STORE```  \nOtherwise the class cannot be instanized by function ```instanize```\n### Inject\nUse ```@Inject(...Providers)``` decorator to inject providers(functions) to class.   \nThe inputed providers will be used to construct instance of decorated class.  \n\u003csmall\u003eNOTE: the sequence of providers is NOT restricted\u003c/small\u003e\n### Component\nUse ```@Component(config: componentConfig)``` to decorate class.  \npass [componentConfig](#componentConfig) to decorator to determine the specific providers for constructing class instance.\n\n### bootstrap()\nExample: ``` bootstrap({ provider: [...Function] }); ```\nThis is where **intanizing** started.  \nThe instanzing function will generate instaces of inputed Providers and store them to ```INSTANCE_STORE``` as global instance.\n\n### construct(Component)\nThe function returns an instance which all dependencies has been injected.\n\n### instanize(InjectableClass)\nThe function returns an instance of registered injectable class.\n\n### componentConfig\n```javascript\n    {\n        restrict?: boolean,\n        provider: [Function|providerConfig]\n    }\n```\n\u003csmall\u003eNOTE: In restrict mode, if the dependency instance cannot be found, it will throw an Error. Otherwise it will return null\u003c/small\u003e\n\n### providerConfig\n```javascript\n    {\n        provider: Function,\n        useValue?: any,\n        useClass?: Function,\n        useExistInstance?: any\n    }\n```\nThe priority is useClass \u003e useValue \u003e useExistInstance\n\n## Examples\n\u003csmall\u003eThe index.web.js has exposed a global variable ```DI```, use \u0026lt;script\u0026gt; tag to import index.web.js\u003c/small\u003e\n\n### index.html\n```html\n    \u003chtml\u003e\n        \u003chead\u003e\u003c/head\u003e\n        \u003cbody\u003e\n            \u003cscript src=\"path/to/your/index.web.js\"\u003e\u003c/script\u003e\n            \u003cscript src=\"your/own/js/my.js\"\u003e\u003c/script\u003e\n        \u003c/body\u003e\n    \u003c/html\u003e\n```\n\n### my.ts\n```javascript\n    @Injectable()\n    class Wheel { \n        showInfo(){ console.log('Wheel module is working OK...') };\n    }\n\n    @Injectable()\n    class Engine {\n        showInfo(){ console.log('Engine module is working OK...') };\n    }\n\n    @Injectable()\n    class V12Engine {\n        showInfo(){ console.log('V12 Engine starts!') }\n    }\n\n\n    @Component({\n        provider: [\n            { provider: Engine, useClass: V12Engine }\n        ]\n    })\n    class Car {\n        constructor( private wheel: Wheel, private engine: V12Engine ) {\n            this.wheel.showInfo();\n            this.engine.showInfo();\n        }\n    }\n\n\n    boostrap({\n        provider: [\n            Wheel,\n            Engine,\n            V12Engine\n        ]\n    });\n\n    var car = new Car( new Wheel(), new Engine() );\n    var racingCar = constrct(Car);\n```\n\n### Console\n```\n    Wheel module is working OK...\n    Engine module is working OK...\n    Wheel module is working OK...\n    V12 Engine starts!\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzixiaowang%2Fdi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzixiaowang%2Fdi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzixiaowang%2Fdi/lists"}