di-go/types.go
2019-11-13 23:08:33 +09:00

46 lines
1.2 KiB
Go

package di
// @Inject(name? string)
import (
"reflect"
"git.loafle.net/loafer/annotation-go"
)
func init() {
if err := annotation.Register(ComponentAnnotationType); nil != err {
panic(err)
}
if err := annotation.Register(InjectAnnotationType); nil != err {
panic(err)
}
if err := annotation.Register(ResourceAnnotationType); nil != err {
panic(err)
}
}
var ComponentAnnotationType = reflect.TypeOf((*ComponentAnnotation)(nil))
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
}
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"`
}