di-go/types.go

40 lines
1.1 KiB
Go
Raw Normal View History

2019-11-13 14:01:03 +00:00
package di
2019-11-13 13:34:36 +00:00
// @Inject(name? string)
import (
"reflect"
"git.loafle.net/loafer/annotation-go"
)
func init() {
annotation.Register(ComponentAnnotationType)
2019-11-13 14:01:03 +00:00
annotation.Register(InjectAnnotationType)
annotation.Register(ResourceAnnotationType)
2019-11-13 13:34:36 +00:00
}
2019-11-13 14:01:03 +00:00
var ComponentAnnotationType = reflect.TypeOf((*ComponentAnnotation)(nil))
2019-11-13 13:34:36 +00:00
type ComponentAnnotation struct {
annotation.TypeAnnotation `@annotation:"@Component"`
Name string `json:"name"`
InitMethod string `json:"initMethod"` // func (receiver interface{}, cr ComponentRegistry) error
DestroyMethod string `json:"destroyMethod"` // func (receiver interface{}, cr ComponentRegistry) error
}
2019-11-13 14:01:03 +00:00
var InjectAnnotationType = reflect.TypeOf((*InjectAnnotation)(nil))
type InjectAnnotation struct {
annotation.TypeAnnotation `@annotation:"@Inject"`
Name string `json:"name"`
}
var ResourceAnnotationType = reflect.TypeOf((*ResourceAnnotation)(nil))
type ResourceAnnotation struct {
annotation.TypeAnnotation `@annotation:"@Resource"`
Name string `json:"name"`
}