2005-01-07
一个比picocontainer更小的IOC容器(已更新到0.2)
又一个IOC容器,Mcc微型组件容器。
特性
===
1、IOC type2和IOC type3 依赖注入
2、组件依赖性检查
3、组件自动装配
4、运行期动态注入
5、函数返回值注入(即工厂方法注入)
6、支持简单的组件生存期管理
Mcc 0.2 (2005.01.09)
====================
Change Log
----------
1、为ComponentDescriber类添加setProperty(RuntimeParameter parameter);
2、为ComponentDescriber类添加setInitMethod方法和setDestroyMethod支持组件的生存期管理;
3、为ComponentManager类添加destroy方法,可以手动销毁ComponentManager实例;
4、为ComponentAdapter类添加destroy方法,在组件管理者销毁时销毁组件实例;
5、实现了依赖检查;
6、解决在一个组件创建过程中某个组件需要被注入多次,创建多个实例的问题。
附件中是源代码,只有在登录后才可下载
特性
===
1、IOC type2和IOC type3 依赖注入
2、组件依赖性检查
3、组件自动装配
4、运行期动态注入
5、函数返回值注入(即工厂方法注入)
6、支持简单的组件生存期管理
Mcc 0.2 (2005.01.09)
====================
Change Log
----------
1、为ComponentDescriber类添加setProperty(RuntimeParameter parameter);
2、为ComponentDescriber类添加setInitMethod方法和setDestroyMethod支持组件的生存期管理;
3、为ComponentManager类添加destroy方法,可以手动销毁ComponentManager实例;
4、为ComponentAdapter类添加destroy方法,在组件管理者销毁时销毁组件实例;
5、实现了依赖检查;
6、解决在一个组件创建过程中某个组件需要被注入多次,创建多个实例的问题。
附件中是源代码,只有在登录后才可下载
评论
dudo
2005-01-08
引用
而且我的感觉就是运行期注入仅仅帮我自动调用了一些setter而已,我不知道还有什么其他的好处没有,所以问了这样一个问题。。。
确实是这样的,测试用例中的例子是很简单的,在一些依赖比较复杂的情况下,这样,在一定程度上简化代码。
还有,你如果在运行期手动注入依赖,那么你无法再切换这个依赖的实现,因为你已经在代码中写死了。而通过这种动态参数注入方式,你可以通过修改配置来切换这个依赖的具体实现。比如例子中的father如果运用参数的动态注入,在运行期只需要注入father的名称,即可自动将father注入child,以后通过修改配置,可以切换这个father的具体实现。
de3light
2005-01-08
dudo 写道
运行期注入用于这种情况: 我们要获取的组件依赖于其他的组件,而该组件的创建可能依赖于一些参数或组件,这些参数和组件需要在运行时才能确定。Mcc提供运行期注入就是解决这个问题。如果没有这个功能的支持,在这种情况下,我们必须手动创建这个依赖的组件并手动注入。
问题是,testcase里面的代码,child依赖的组件father 和 mother
[code:1] Man father = new Man();
father.setName("mike");
Women mother = new Women();
mother.setName("marry"); [/code:1]
也是我自己手动创建的啊,容器又帮不了忙的,容器也不可能帮我创建这些运行时才能确定的bean。而且我的感觉就是运行期注入仅仅帮我自动调用了一些setter而已,我不知道还有什么其他的好处没有,所以问了这样一个问题。。。
dudo
2005-01-07
运行期注入用于这种情况: 我们要获取的组件依赖于其他的组件,而该组件的创建可能依赖于一些参数或组件,这些参数和组件需要在运行时才能确定。Mcc提供运行期注入就是解决这个问题。如果没有这个功能的支持,在这种情况下,我们必须手动创建这个依赖的组件并手动注入。
de3light
2005-01-07
很简洁的容器,
稍稍看了一下源代码,跑了一下testcase ,有个地方不太明白
[code:1] public void testRuntimeParameters(){
ComponentDescriberManager cdm = new ComponentDescriberManager();
ComponentDescriber cd = cdm.registerComponent("child",Child.class);
cd.setProperty("name",cdm.runtime());
cd.setProperty("father",cdm.runtime());
cd.setProperty("mother",cdm.runtime());
ComponentManager cm = ComponentFactory.newComponentManager(cdm);
Man father = new Man();
father.setName("mike");
Women mother = new Women();
mother.setName("marry");
Child child = (Child)cm.getComponent("child",new Object[]{"john",father,mother});
assertNotNull("Component child not found!", child);
assertEquals(father, child.getFather());
assertEquals(mother, child.getMother());
}[/code:1]
这里实现的运行期动态注入的功能和我用
[code:1] Child child = (Child)cm.getComponent("child")
child.setFather(father);
child.setMother(mother);[/code:1]
这样做有什么不同?或者说让容器来注入比我手工注入有什么好处么?仅仅是确保需要的bean引用都有效?谢谢
[code:1] public void testRuntimeParameters(){
ComponentDescriberManager cdm = new ComponentDescriberManager();
ComponentDescriber cd = cdm.registerComponent("child",Child.class);
cd.setProperty("name",cdm.runtime());
cd.setProperty("father",cdm.runtime());
cd.setProperty("mother",cdm.runtime());
ComponentManager cm = ComponentFactory.newComponentManager(cdm);
Man father = new Man();
father.setName("mike");
Women mother = new Women();
mother.setName("marry");
Child child = (Child)cm.getComponent("child",new Object[]{"john",father,mother});
assertNotNull("Component child not found!", child);
assertEquals(father, child.getFather());
assertEquals(mother, child.getMother());
}[/code:1]
这里实现的运行期动态注入的功能和我用
[code:1] Child child = (Child)cm.getComponent("child")
child.setFather(father);
child.setMother(mother);[/code:1]
这样做有什么不同?或者说让容器来注入比我手工注入有什么好处么?仅仅是确保需要的bean引用都有效?谢谢
buaawhl
2005-01-07
好。大致看了一下,感觉代码整洁漂亮。用法也很直观简单。
- 浏览: 15406 次
- 性别:

- 来自: 深圳

- 详细资料
搜索本博客
最近加入圈子
最新评论
-
新一代的Web表现层开发方 ...
表现层真是越来越重要了, 以前一直搞服务器端,对客户端的东西不屑一顾, 现在大有 ...
-- by giscat -
新一代的Web表现层开发方 ...
dudo 写道: 目前基于jav ...
-- by SteveGY -
新一代的Web表现层开发方 ...
楼主看一下JSF吧,不要瞎忙乎了
-- by JavaInActoin -
新一代的Web表现层开发方 ...
studying...
-- by qy33 -
新一代的Web表现层开发方 ...
期待实际的例子!学习中。。
-- by pengjun_lovecoding@hotmail.com






评论排行榜