-
Notifications
You must be signed in to change notification settings - Fork 17
Open
Description
构造函数注入时,有循环依赖
场景demo
ioc.create({
A: {
creator: function(instanceB) { this.b = instanceB }
args: [{ $ref : 'B' }]
},
B: {
creator: function(instanceA) { this.a = instanceA }
args: [{ $ref : 'A' }]
}
});
ioc.getComponent('A', function(a){ //... });可能的策略
- 抛异常
- 将依赖设置为 null传入, 控制台丢警告
setter 注入时,有循环依赖
场景demo
ioc.create({
A: {
creator: function() { // ... },
properties: { b: { $ref: 'B' } }
},
B: {
creator: function() { // ... },
properties: { a: { $ref: 'A' } }
}
});
ioc.getComponent('A', function(a){ //... });可能的策略
控制台发警告,同时创建好依赖实例后,调用对应 setter 传入实例即可,注入这块不会存在无限递归问题。
Metadata
Metadata
Assignees
Labels
No labels