Documentation
      ¶
    
    
  
    
  
    Index ¶
- Constants
 - Variables
 - func New() gs.Container
 - func NewBean(objOrCtor interface{}, ctorArgs ...gs.Arg) *gs.BeanDefinition
 - type ArgContext
 - func (a *ArgContext) Bind(v reflect.Value, tag string) error
 - func (a *ArgContext) Find(s gs.BeanSelectorInterface) ([]gs.CondBean, error)
 - func (a *ArgContext) Has(key string) bool
 - func (a *ArgContext) Matches(c gs.Condition) (bool, error)
 - func (a *ArgContext) Prop(key string, def ...string) string
 - func (a *ArgContext) Wire(v reflect.Value, tag string) error
 
- type BeanRuntime
 - type Container
 - func (c *Container) Bind(i interface{}, tag ...string) error
 - func (c *Container) Close()
 - func (c *Container) Get(i interface{}, tag ...string) error
 - func (c *Container) Go(fn func(ctx context.Context))
 - func (c *Container) GroupRegister(fn GroupFunc)
 - func (c *Container) Has(key string) bool
 - func (c *Container) Invoke(fn interface{}, args ...gs.Arg) ([]interface{}, error)
 - func (c *Container) Keys() []string
 - func (c *Container) Object(i interface{}) *gs.RegisteredBean
 - func (c *Container) Prop(key string, def ...string) string
 - func (c *Container) Provide(ctor interface{}, args ...gs.Arg) *gs.RegisteredBean
 - func (c *Container) Refresh() (err error)
 - func (c *Container) RefreshProperties(p gs.Properties) error
 - func (c *Container) Register(b *gs.BeanDefinition) *gs.RegisteredBean
 - func (c *Container) ReleaseUnusedMemory()
 - func (c *Container) Resolve(s string) (string, error)
 - func (c *Container) SubKeys(key string) ([]string, error)
 - func (c *Container) Wire(objOrCtor interface{}, ctorArgs ...gs.Arg) (interface{}, error)
 
- type GroupFunc
 - type WiringStack
 
Constants ¶
const ( RefreshDefault = refreshState(iota) // 未刷新 RefreshInit // 准备刷新 Refreshing // 正在刷新 Refreshed // 已刷新 )
Variables ¶
Functions ¶
Types ¶
type ArgContext ¶
type ArgContext struct {
	// contains filtered or unexported fields
}
    ArgContext holds a Container and a WiringStack to manage dependency injection.
func NewArgContext ¶
func NewArgContext(c *Container, stack *WiringStack) *ArgContext
NewArgContext creates a new ArgContext with a given Container and WiringStack.
func (*ArgContext) Bind ¶
func (a *ArgContext) Bind(v reflect.Value, tag string) error
Bind binds a value to a specific tag in the container.
func (*ArgContext) Find ¶
func (a *ArgContext) Find(s gs.BeanSelectorInterface) ([]gs.CondBean, error)
func (*ArgContext) Has ¶
func (a *ArgContext) Has(key string) bool
type BeanRuntime ¶
type Container ¶
type Container struct {
	ContextAware bool
	AllowCircularReferences bool `value:"${spring.allow-circular-references:=false}"`
	ForceAutowireIsNullable bool `value:"${spring.force-autowire-is-nullable:=false}"`
	// contains filtered or unexported fields
}
    Container 是 go-spring 框架的基石,实现了 Martin Fowler 在 << Inversion of Control Containers and the Dependency Injection pattern >> 一文中 提及的依赖注入的概念。但原文的依赖注入仅仅是指对象之间的依赖关系处理,而有些 IoC 容器在实现时比如 Spring 还引入了对属性 property 的处理。通常大家会用依赖注入统 述上面两种概念,但实际上使用属性绑定来描述对 property 的处理会更加合适,因此 go-spring 严格区分了这两种概念,在描述对 bean 的处理时要么单独使用依赖注入或属 性绑定,要么同时使用依赖注入和属性绑定。
func (*Container) Bind ¶
Bind binds the value of the specified key to the provided struct or variable.
func (*Container) Close ¶
func (c *Container) Close()
Close closes the container and cleans up resources.
func (*Container) Go ¶
Go runs the provided function in a new goroutine. When the container is closed, the context.Context will be canceled.
func (*Container) GroupRegister ¶
func (*Container) Object ¶
func (c *Container) Object(i interface{}) *gs.RegisteredBean
Object 注册对象形式的 bean ,需要注意的是该方法在注入开始后就不能再调用了。
func (*Container) Prop ¶
Prop retrieves the value of the specified key from the container's properties.
func (*Container) Provide ¶
func (c *Container) Provide(ctor interface{}, args ...gs.Arg) *gs.RegisteredBean
Provide 注册构造函数形式的 bean ,需要注意的是该方法在注入开始后就不能再调用了。
func (*Container) RefreshProperties ¶
func (c *Container) RefreshProperties(p gs.Properties) error
RefreshProperties updates the properties of the container.
func (*Container) Register ¶
func (c *Container) Register(b *gs.BeanDefinition) *gs.RegisteredBean
func (*Container) ReleaseUnusedMemory ¶
func (c *Container) ReleaseUnusedMemory()
ReleaseUnusedMemory releases unused memory by cleaning up unnecessary resources.
type GroupFunc ¶
type GroupFunc = func(p gs.Properties) ([]*gs.BeanDefinition, error)
type WiringStack ¶
type WiringStack struct {
	// contains filtered or unexported fields
}
    WiringStack tracks the injection path of beans and their destroyers.
func NewWiringStack ¶
func NewWiringStack() *WiringStack
NewWiringStack creates a new WiringStack instance.