di/registry/registry_test.go

58 lines
1.3 KiB
Go
Raw Normal View History

2017-12-05 13:28:42 +00:00
package registry
import (
2017-12-08 10:32:59 +00:00
"log"
2017-12-05 13:28:42 +00:00
"reflect"
"testing"
2018-03-15 13:19:44 +00:00
"git.loafle.net/commons_go/di/annotation"
2018-03-15 13:49:25 +00:00
cdia "git.loafle.net/commons_go/di/injection/annotation"
2017-12-05 13:28:42 +00:00
)
func TestRegisterType(t *testing.T) {
2018-03-15 13:19:44 +00:00
RegisterType(reflect.TypeOf((*AService)(nil)))
RegisterType(reflect.TypeOf((*BService)(nil)))
2017-12-08 10:32:59 +00:00
// 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"})
2018-03-15 13:49:25 +00:00
css := GetInstancesByAnnotationName(cdia.ComponentTag)
log.Printf("%v", css)
2018-03-15 14:08:51 +00:00
css2 := GetInstances([]reflect.Type{
reflect.TypeOf((*AService)(nil)),
reflect.TypeOf((*BService)(nil)),
})
log.Printf("%v", css2)
2018-03-15 13:19:44 +00:00
2018-03-15 14:08:51 +00:00
cs := GetInstance(reflect.TypeOf((*CService)(nil))).(*CService)
2018-03-15 13:19:44 +00:00
log.Printf("%v", cs)
2017-12-08 10:32:59 +00:00
2017-12-05 13:28:42 +00:00
}
2017-12-08 10:32:59 +00:00
type AService struct {
2018-03-15 13:19:44 +00:00
annotation.TypeAnnotation `annotation:"@Component(name=dkdkdf)"`
2017-12-08 10:32:59 +00:00
NameA string
2017-12-06 00:48:03 +00:00
}
2017-12-08 10:32:59 +00:00
type BService struct {
2018-03-15 13:19:44 +00:00
annotation.TypeAnnotation `annotation:"@Component()"`
2017-12-08 10:32:59 +00:00
NameB string
2017-12-06 00:48:03 +00:00
}
2017-12-08 10:32:59 +00:00
type CService struct {
AService *AService `annotation:"@Inject()"`
BService *BService `annotation:"@Inject()"`
List []string `annotation:"@Resource()"`
2017-12-05 13:28:42 +00:00
}