ing
This commit is contained in:
parent
e1da1222c6
commit
dc36d262ae
|
@ -19,7 +19,7 @@ func init() {
|
|||
var registry ComponentRegistry
|
||||
|
||||
type ComponentRegistry interface {
|
||||
RegisterType(t reflect.Type) error
|
||||
RegisterType(t reflect.Type)
|
||||
RegisterResource(name string, resource interface{}) error
|
||||
|
||||
GetInstance(t reflect.Type) (interface{}, error)
|
||||
|
@ -45,30 +45,30 @@ type defaultComponentRegistry struct {
|
|||
resourceByName map[string]interface{}
|
||||
}
|
||||
|
||||
func RegisterType(t reflect.Type) error {
|
||||
func RegisterType(t reflect.Type) {
|
||||
pc, _, _, ok := runtime.Caller(1)
|
||||
details := runtime.FuncForPC(pc)
|
||||
if ok && details != nil {
|
||||
log.Printf("called from %s", details.Name())
|
||||
}
|
||||
|
||||
return registry.RegisterType(t)
|
||||
registry.RegisterType(t)
|
||||
}
|
||||
func (cr *defaultComponentRegistry) RegisterType(t reflect.Type) error {
|
||||
func (cr *defaultComponentRegistry) RegisterType(t reflect.Type) {
|
||||
if nil == t {
|
||||
return fmt.Errorf("DI: t[reflect.Type] is nil")
|
||||
log.Panicf("DI: t[reflect.Type] is nil")
|
||||
}
|
||||
if !cur.IsTypeKind(t, reflect.Struct, true) {
|
||||
return fmt.Errorf("DI: t[reflect.Type] must be specified but is %v", t)
|
||||
log.Panicf("DI: t[reflect.Type] must be specified but is %v", t)
|
||||
}
|
||||
|
||||
td, err := cr.buildDefinition(t)
|
||||
if nil != err {
|
||||
return fmt.Errorf("DI: %v", err)
|
||||
log.Panicf("DI: %v", err)
|
||||
}
|
||||
|
||||
if _, ok := cr.definitionByType[td.RealType]; ok {
|
||||
return fmt.Errorf("DI: The type[%s] of Component is exist already", td.FullName)
|
||||
log.Panicf("DI: The type[%s] of Component is exist already", td.FullName)
|
||||
}
|
||||
cr.definitionByType[td.RealType] = td
|
||||
|
||||
|
@ -82,11 +82,9 @@ func (cr *defaultComponentRegistry) RegisterType(t reflect.Type) error {
|
|||
}
|
||||
|
||||
if eTD, ok := cr.definitionByName[name]; ok {
|
||||
return fmt.Errorf("DI: The name[%s] of Component is exist already type[%s]", name, eTD.FullName)
|
||||
log.Panicf("DI: The name[%s] of Component is exist already type[%s]", name, eTD.FullName)
|
||||
}
|
||||
cr.definitionByName[name] = td
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func RegisterResource(name string, resource interface{}) error {
|
||||
|
|
Loading…
Reference in New Issue
Block a user