Documentation ¶
Index ¶
- Variables
- func AddInitializingBean(handler InitializingBeanHandler)
- func AddInitializingBeanFunc(handler func())
- func Autowired(is ...interface{})
- func Check() error
- func GetByName(namespace string) (interface{}, bool)
- func GetListByName(namespaces ...string) []interface{}
- func Injection(i interface{})
- func InjectionDefault(i interface{})
- func RegisterByName(namespace string, m interface{})
- type Container
- type InitializingBeanHandler
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( //Default 默认的bean Default = NewContainer() )
Functions ¶
func AddInitializingBean ¶
func AddInitializingBean(handler InitializingBeanHandler)
AddInitializingBean 注册完成回调接口, 执行check成功后会调用回调接口
func AddInitializingBeanFunc ¶
func AddInitializingBeanFunc(handler func())
AddInitializingBeanFunc 注册完成回调方法, 执行check成功后会调用回调方法
func Autowired ¶
func Autowired(is ...interface{})
AutowiredManager 声明需要注入的接口变量 如果目标接口还没有注入实例,会在注入后给将接口实例赋值给指针 如果目标接口类型已经被注入,会立刻获得有效的接口实例
Example ¶
package main import "fmt" type NameInterface interface { DO() } type TestImpl struct { name string } func (t *TestImpl) DO() { fmt.Println("do by:", t.name) } func init() { var nameInterface NameInterface // 这里一定要要用指针 Autowired(&nameInterface) AddInitializingBeanFunc(func() { fmt.Println("auto wired done") nameInterface.DO() }) } func main() { t := &TestImpl{name: "demo bean"} // 转换成注入目标的类型 var i NameInterface = t // 这里也要用指针,否则反射识别类型会出问题 Injection(&i) // 检查是否有缺失 err := Check() if err != nil { panic(err) } }
Output:
func GetListByName ¶
func GetListByName(namespaces ...string) []interface{}
func InjectionDefault ¶
func InjectionDefault(i interface{})
InjectionDefault 注入一个构造好的默认实例 * 如果注入多个相同接口类型,后注入的实例会覆盖先注入的实例,default实例不会覆盖普通实例
func RegisterByName ¶
func RegisterByName(namespace string, m interface{})
Types ¶
type Container ¶
type Container interface { Autowired(p interface{}) Injection(i interface{}) InjectionDefault(i interface{}) Check() error AddInitializingBean(handler InitializingBeanHandler) AddInitializingBeanFunc(handler func()) }
Container bean 容器接口
type InitializingBeanHandler ¶
type InitializingBeanHandler interface {
AfterPropertiesSet()
}
InitializingBeanHandler 注入完成后的回调
Click to show internal directories.
Click to hide internal directories.