gs_core

package
v1.2.0-rc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 15, 2025 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RefreshDefault = refreshState(iota) // 未刷新
	RefreshInit                         // 准备刷新
	Refreshing                          // 正在刷新
	Refreshed                           // 已刷新
)

Variables

View Source
var (
	GsContextType = reflect.TypeOf((*gs.Context)(nil)).Elem()
)

Functions

func New

func New() gs.Container

New 创建 IoC 容器。

func NewBean

func NewBean(objOrCtor interface{}, ctorArgs ...gs.Arg) *gs.BeanDefinition

NewBean 普通函数注册时需要使用 reflect.ValueOf(fn) 形式以避免和构造函数发生冲突。

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 (*ArgContext) Has

func (a *ArgContext) Has(key string) bool

func (*ArgContext) Matches

func (a *ArgContext) Matches(c gs.Condition) (bool, error)

Matches checks if a given condition matches the container.

func (*ArgContext) Prop

func (a *ArgContext) Prop(key string, def ...string) string

func (*ArgContext) Wire

func (a *ArgContext) Wire(v reflect.Value, tag string) error

Wire wires a value based on a specific tag in the container.

type BeanRuntime

type BeanRuntime interface {
	Name() string
	Type() reflect.Type
	Value() reflect.Value
	Interface() interface{}
	Callable() gs.Callable
	Status() gs_bean.BeanStatus
	String() string
}

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

func (c *Container) Bind(i interface{}, tag ...string) error

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) Get

func (c *Container) Get(i interface{}, tag ...string) error

Get retrieves a bean of the specified type using the provided selector.

func (*Container) Go

func (c *Container) Go(fn func(ctx context.Context))

Go runs the provided function in a new goroutine. When the container is closed, the context.Context will be canceled.

func (*Container) GroupRegister

func (c *Container) GroupRegister(fn GroupFunc)

func (*Container) Has

func (c *Container) Has(key string) bool

Has checks if a key exists in the container's properties.

func (*Container) Invoke

func (c *Container) Invoke(fn interface{}, args ...gs.Arg) ([]interface{}, error)

Invoke calls the provided function with the specified arguments.

func (*Container) Keys

func (c *Container) Keys() []string

Keys returns all keys present in the container's properties.

func (*Container) Object

func (c *Container) Object(i interface{}) *gs.RegisteredBean

Object 注册对象形式的 bean ,需要注意的是该方法在注入开始后就不能再调用了。

func (*Container) Prop

func (c *Container) Prop(key string, def ...string) string

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) Refresh

func (c *Container) Refresh() (err error)

Refresh initializes and wires all beans in the container.

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.

func (*Container) Resolve

func (c *Container) Resolve(s string) (string, error)

Resolve resolves placeholders or references in the given string.

func (*Container) SubKeys

func (c *Container) SubKeys(key string) ([]string, error)

SubKeys returns sub-keys under the specified key in the container's properties.

func (*Container) Wire

func (c *Container) Wire(objOrCtor interface{}, ctorArgs ...gs.Arg) (interface{}, error)

Wire creates and returns a wired bean using the provided object or constructor function.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL