ing
This commit is contained in:
parent
dc36d262ae
commit
2c6cdb51dc
|
@ -117,27 +117,31 @@ func (cr *defaultComponentRegistry) GetInstance(t reflect.Type) (interface{}, er
|
||||||
return nil, fmt.Errorf("DI: t[reflect.Type] must be pointer of struct")
|
return nil, fmt.Errorf("DI: t[reflect.Type] must be pointer of struct")
|
||||||
}
|
}
|
||||||
|
|
||||||
var err error
|
var (
|
||||||
|
td *TypeDefinition
|
||||||
|
comV interface{}
|
||||||
|
ok bool
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
|
||||||
rt, _, _ := cur.GetTypeInfo(t)
|
rt, _, _ := cur.GetTypeInfo(t)
|
||||||
td, ok := cr.definitionByType[rt]
|
if td, ok = cr.definitionByType[rt]; !ok {
|
||||||
if !ok {
|
if td, err = cr.buildDefinition(t); nil != err {
|
||||||
td, err = cr.buildDefinition(t)
|
|
||||||
if nil != err {
|
|
||||||
return nil, fmt.Errorf("DI: %v", err)
|
return nil, fmt.Errorf("DI: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
comV, ok := cr.instanceByType[td.RealType]
|
if comV, ok = cr.instanceByType[td.RealType]; ok {
|
||||||
if ok {
|
|
||||||
return comV, nil
|
return comV, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
v := reflect.New(rt)
|
v := reflect.New(rt)
|
||||||
rv := v.Elem()
|
rv := v.Elem()
|
||||||
|
|
||||||
var annotation cda.Annotation
|
var (
|
||||||
var fV interface{}
|
annotation cda.Annotation
|
||||||
|
fV interface{}
|
||||||
|
)
|
||||||
|
|
||||||
for _, fd := range td.Fields {
|
for _, fd := range td.Fields {
|
||||||
f := rv.FieldByName(fd.FieldName)
|
f := rv.FieldByName(fd.FieldName)
|
||||||
|
@ -150,8 +154,7 @@ func (cr *defaultComponentRegistry) GetInstance(t reflect.Type) (interface{}, er
|
||||||
}
|
}
|
||||||
|
|
||||||
if annotation = fd.GetAnnotationByType(reflect.TypeOf((*cdia.Inject)(nil)), false); nil != annotation {
|
if annotation = fd.GetAnnotationByType(reflect.TypeOf((*cdia.Inject)(nil)), false); nil != annotation {
|
||||||
fV, err = cr.GetInstance(fd.Type)
|
if fV, err = cr.GetInstance(fd.Type); nil != err {
|
||||||
if nil != err {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -161,8 +164,7 @@ func (cr *defaultComponentRegistry) GetInstance(t reflect.Type) (interface{}, er
|
||||||
if "" == n {
|
if "" == n {
|
||||||
n = fd.FieldName
|
n = fd.FieldName
|
||||||
}
|
}
|
||||||
fV, err = cr.GetInstanceByName(n)
|
if fV, err = cr.GetInstanceByName(n); nil != err {
|
||||||
if nil != err {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -201,8 +203,7 @@ func (cr *defaultComponentRegistry) GetInstances(ts []reflect.Type) ([]interface
|
||||||
)
|
)
|
||||||
instances := make([]interface{}, 0)
|
instances := make([]interface{}, 0)
|
||||||
for _, t := range ts {
|
for _, t := range ts {
|
||||||
i, err = cr.GetInstance(t)
|
if i, err = cr.GetInstance(t); nil != err {
|
||||||
if nil != err {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
instances = append(instances, i)
|
instances = append(instances, i)
|
||||||
|
@ -225,8 +226,7 @@ func (cr *defaultComponentRegistry) GetInstancesByAnnotationName(n string) ([]in
|
||||||
|
|
||||||
for _, td := range cr.definitionByType {
|
for _, td := range cr.definitionByType {
|
||||||
if nil != td.GetAnnotation(n) {
|
if nil != td.GetAnnotation(n) {
|
||||||
i, err = cr.GetInstance(td.Type)
|
if i, err = cr.GetInstance(td.Type); nil != err {
|
||||||
if nil != err {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
instances = append(instances, i)
|
instances = append(instances, i)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user