{"id":29926581,"url":"https://github.com/ecomfe/uioc","last_synced_at":"2025-08-02T12:42:22.427Z","repository":{"id":16667520,"uuid":"19423213","full_name":"ecomfe/uioc","owner":"ecomfe","description":"IoC Framework for us","archived":false,"fork":false,"pushed_at":"2017-10-13T05:37:49.000Z","size":1259,"stargazers_count":115,"open_issues_count":7,"forks_count":17,"subscribers_count":20,"default_branch":"develop","last_synced_at":"2025-07-16T01:37:06.666Z","etag":null,"topics":["aop","ioc","javascript"],"latest_commit_sha":null,"homepage":null,"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/ecomfe.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":"2014-05-04T09:29:49.000Z","updated_at":"2022-08-11T17:36:30.000Z","dependencies_parsed_at":"2022-08-28T00:52:31.522Z","dependency_job_id":null,"html_url":"https://github.com/ecomfe/uioc","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/ecomfe/uioc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecomfe%2Fuioc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecomfe%2Fuioc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecomfe%2Fuioc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecomfe%2Fuioc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ecomfe","download_url":"https://codeload.github.com/ecomfe/uioc/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecomfe%2Fuioc/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268392148,"owners_count":24243297,"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-02T02:00:12.353Z","response_time":74,"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":["aop","ioc","javascript"],"created_at":"2025-08-02T12:42:07.468Z","updated_at":"2025-08-02T12:42:22.406Z","avatar_url":"https://github.com/ecomfe.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"uioc ![building status](https://travis-ci.org/ecomfe/uioc.svg?branch=master) \n===\n\n# 关于\nuioc是用JavaScript写的一个轻量级IoC容器，为JavaScript应用提供了IoC功能。通过使用配置的方式管理模块依赖，最大程度的提高了模块的复用性。\n\n在1.0版本中，增加了aop的支持，对应用从横向关注点上提供了复用支持。\n\n# 安装\n\n```shell\nnpm install uioc —save\n```\n# 基本使用\n\n## Step 1：定义模块\n\nIoC最大的要求之一就是不要在模块中引入具体依赖的实现，对应在JavaScript中则是不要显示的引入依赖模块，仅在注入点面向依赖接口编程。\n\n```javascript\n// List.js\nexport default class List {\n    // 构造函数注入实现了ListModel接口的依赖\n    constructor(listModel) {\n        this.model = listModel;\n    }\n\n    // 属性/接口注入实现了ListView接口的依赖\n    setView(listView) {\n        this.view = listView;\n    }\n\n    enter() {\n        let data = this.model.load();\n        this.view.render(data);\n    }\n}\n\n// MyListModel.js\nexport default class MyListModel {\n    load() {\n        return {data: 'data'};\n    }\n}\n\n// MyListView.js\nexport default class MyListView {\n    render(data) {\n        console.log(data);\n    }\n}\n```\n上述代码中在List类有两个依赖view和model，分别实现了ListModel和ListView（隐式）接口，\n而MyListModel和MyListView类则是ListModel与ListView接口的具体实现。\n\n## Step 2：定义IoC配置，实例化IoC容器\n\n```javascript\n// ioc.js\nimport {IoC} from 'uioc';\nimport List from './List';\nimport MyListModel from './MyListModel';\nimport MyListView from './MyListView';\n\nlet config = {\n    components: {\n        list: {\n            creator: List,\n            args: [\n                {$ref: 'listModel'}\n            ],\n            properties: {\n                view: {\n                    $ref: {'listView'}\n                }\n            },\n\n            listModel: {\n                creator: MyListModel\n            },\n\n            listView: {\n                creator: MyListView\n            }\n        }\n    }\n};\n\nlet ioc = new IoC(config);\n\nexport default ioc;\n```\n\n上述代码中，声明了list, listModel, listView三个组件，\n其中list通过$ref关键字声明了2个依赖：listModel是list的构造函数依赖，\n会在实例化list的时候，将创建好的listModel依赖传入构造函数；\nlistView是list的属性依赖，会在实例化list完成后，将创建好的listView赋值给list，赋值方式为有setter则调用setter，无setter则直接对象赋值。\n\n## Step 3:  定义入口文件，从ioc实例获取入口组件启动整个应用\n\n```javascript\n// main.js\nimport ioc from 'ioc';\n\nioc.getComponent('list').then(list =\u003e list.enter());\n```\n上述代码中通过ioc容器实例获取了list组件，ioc容器将根据配置创建好list的相关依赖并注入给list，最终组装成完整的list实例传递给promise的resolve回调。\n\n# [基础特性](https://github.com/ecomfe/uioc/wiki/Base-Feature)\n\n# 高级特性\n\n- [插件机制](https://github.com/ecomfe/uioc/wiki/plugins)\n- [aop](https://github.com/ecomfe/uioc/wiki/aop)\n\n# [API](http://ecomfe.github.io/uioc/doc/)\n\n# [Changelog](https://github.com/ecomfe/uioc/wiki/Changelog)\n\n# [0.3.x版本文档](https://github.com/ecomfe/uioc/wiki/0.3.x-readme)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fecomfe%2Fuioc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fecomfe%2Fuioc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fecomfe%2Fuioc/lists"}