58 lines
1.3 KiB
Go
58 lines
1.3 KiB
Go
package registry
|
|
|
|
import (
|
|
"log"
|
|
"reflect"
|
|
"testing"
|
|
|
|
"git.loafle.net/commons_go/di/annotation"
|
|
cdia "git.loafle.net/commons_go/di/injection/annotation"
|
|
)
|
|
|
|
func TestRegisterType(t *testing.T) {
|
|
RegisterType(reflect.TypeOf((*AService)(nil)))
|
|
RegisterType(reflect.TypeOf((*BService)(nil)))
|
|
// RegisterType(reflect.TypeOf((*TestStruct2)(nil)), &cda.ComponentAnnotation{
|
|
// Name: "test1",
|
|
// })
|
|
// RegisterType(reflect.TypeOf((*TestStruct3)(nil)), &cda.ComponentAnnotation{
|
|
// Name: "test2",
|
|
// })
|
|
|
|
// fs := getFields(reflect.TypeOf((*TestStruct3)(nil)))
|
|
// log.Printf("%v", fs)
|
|
|
|
RegisterResource("List", []string{"dfdkf", "skgkfg"})
|
|
|
|
css := GetInstancesByAnnotationName(cdia.ComponentTag)
|
|
log.Printf("%v", css)
|
|
|
|
css2 := GetInstances([]reflect.Type{
|
|
reflect.TypeOf((*AService)(nil)),
|
|
reflect.TypeOf((*BService)(nil)),
|
|
})
|
|
log.Printf("%v", css2)
|
|
|
|
cs := GetInstance(reflect.TypeOf((*CService)(nil))).(*CService)
|
|
log.Printf("%v", cs)
|
|
|
|
}
|
|
|
|
type AService struct {
|
|
annotation.TypeAnnotation `annotation:"@Component(name=dkdkdf)"`
|
|
|
|
NameA string
|
|
}
|
|
|
|
type BService struct {
|
|
annotation.TypeAnnotation `annotation:"@Component()"`
|
|
|
|
NameB string
|
|
}
|
|
|
|
type CService struct {
|
|
AService *AService `annotation:"@Inject()"`
|
|
BService *BService `annotation:"@Inject()"`
|
|
List []string `annotation:"@Resource()"`
|
|
}
|