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")
|
||||
}
|
||||
|
||||
var err error
|
||||
var (
|
||||
td *TypeDefinition
|
||||
comV interface{}
|
||||
ok bool
|
||||
err error
|
||||
)
|
||||
|
||||
rt, _, _ := cur.GetTypeInfo(t)
|
||||
td, ok := cr.definitionByType[rt]
|
||||
if !ok {
|
||||
td, err = cr.buildDefinition(t)
|
||||
if nil != err {
|
||||
if td, ok = cr.definitionByType[rt]; !ok {
|
||||
if td, err = cr.buildDefinition(t); nil != err {
|
||||
return nil, fmt.Errorf("DI: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
comV, ok := cr.instanceByType[td.RealType]
|
||||
if ok {
|
||||
if comV, ok = cr.instanceByType[td.RealType]; ok {
|
||||
return comV, nil
|
||||
}
|
||||
|
||||
v := reflect.New(rt)
|
||||
rv := v.Elem()
|
||||
|
||||
var annotation cda.Annotation
|
||||
var fV interface{}
|
||||
var (
|
||||
annotation cda.Annotation
|
||||
fV interface{}
|
||||
)
|
||||
|
||||
for _, fd := range td.Fields {
|
||||
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 {
|
||||
fV, err = cr.GetInstance(fd.Type)
|
||||
if nil != err {
|
||||
if fV, err = cr.GetInstance(fd.Type); nil != err {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
@ -161,8 +164,7 @@ func (cr *defaultComponentRegistry) GetInstance(t reflect.Type) (interface{}, er
|
|||
if "" == n {
|
||||
n = fd.FieldName
|
||||
}
|
||||
fV, err = cr.GetInstanceByName(n)
|
||||
if nil != err {
|
||||
if fV, err = cr.GetInstanceByName(n); nil != err {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
@ -201,8 +203,7 @@ func (cr *defaultComponentRegistry) GetInstances(ts []reflect.Type) ([]interface
|
|||
)
|
||||
instances := make([]interface{}, 0)
|
||||
for _, t := range ts {
|
||||
i, err = cr.GetInstance(t)
|
||||
if nil != err {
|
||||
if i, err = cr.GetInstance(t); nil != err {
|
||||
return nil, err
|
||||
}
|
||||
instances = append(instances, i)
|
||||
|
@ -225,8 +226,7 @@ func (cr *defaultComponentRegistry) GetInstancesByAnnotationName(n string) ([]in
|
|||
|
||||
for _, td := range cr.definitionByType {
|
||||
if nil != td.GetAnnotation(n) {
|
||||
i, err = cr.GetInstance(td.Type)
|
||||
if nil != err {
|
||||
if i, err = cr.GetInstance(td.Type); nil != err {
|
||||
return nil, err
|
||||
}
|
||||
instances = append(instances, i)
|
||||
|
|
Loading…
Reference in New Issue
Block a user