This commit is contained in:
crusader 2018-03-16 12:16:23 +09:00
parent 64af0e5f73
commit 70018c51f5
2 changed files with 27 additions and 9 deletions

View File

@ -33,16 +33,15 @@ func (td *TypeDefinition) GetAnnotationByType(at reflect.Type, includeEmbedding
} }
for _, v := range td.TypeAnnotations { for _, v := range td.TypeAnnotations {
if at == reflect.TypeOf(v) {
return v
}
if includeEmbedding { if includeEmbedding {
if checkAnnotation(reflect.TypeOf(v), at) { if checkAnnotation(reflect.TypeOf(v), at) {
return v return v
} }
} else {
if at == reflect.TypeOf(v) {
return v
}
} }
} }
return nil return nil
@ -87,6 +86,26 @@ func (fd *FieldDefinition) GetAnnotation(name string) cda.Annotation {
return fd.Annotations[name] return fd.Annotations[name]
} }
func (fd *FieldDefinition) GetAnnotationByType(at reflect.Type, includeEmbedding bool) cda.Annotation {
if nil == fd.Annotations {
return nil
}
for _, v := range fd.Annotations {
if at == reflect.TypeOf(v) {
return v
}
if includeEmbedding {
if checkAnnotation(reflect.TypeOf(v), at) {
return v
}
}
}
return nil
}
func FullName(pkgName, typeName string) string { func FullName(pkgName, typeName string) string {
return fmt.Sprintf("%s/%s", pkgName, typeName) return fmt.Sprintf("%s/%s", pkgName, typeName)
} }

View File

@ -149,12 +149,11 @@ func (cr *defaultComponentRegistry) GetInstance(t reflect.Type) interface{} {
logging.Logger().Panic(fmt.Sprintf("DI: Field[%s] can not set", fd.FieldName)) logging.Logger().Panic(fmt.Sprintf("DI: Field[%s] can not set", fd.FieldName))
} }
annotation = fd.GetAnnotation(cdia.InjectTag) if annotation = fd.GetAnnotationByType(reflect.TypeOf((*cdia.Inject)(nil)), false); nil != annotation {
if nil != annotation {
fV = cr.GetInstance(fd.Type) fV = cr.GetInstance(fd.Type)
} }
annotation = fd.GetAnnotation(cdia.ResourceTag)
if nil != annotation { if annotation = fd.GetAnnotationByType(reflect.TypeOf((*cdia.Resource)(nil)), false); nil != annotation {
n := annotation.(*cdia.Resource).Name n := annotation.(*cdia.Resource).Name
if "" == n { if "" == n {
n = fd.FieldName n = fd.FieldName