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"
|
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:19:44 +00:00
|
|
|
cs := GetInstance(reflect.TypeOf((*CService)(nil))).(*CService)
|
|
|
|
|
|
|
|
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
|
|
|
}
|