gs_bean

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package gs_bean provides core bean management for Go-Spring framework.

Index

Constants

View Source
const (
	StatusDeleted   = BeanStatus(-1)   // Bean has been deleted.
	StatusDefault   = BeanStatus(iota) // Default status of the bean.
	StatusResolving                    // Bean is being resolved.
	StatusResolved                     // Bean has been resolved.
	StatusCreating                     // Bean is being created.
	StatusCreated                      // Bean has been created.
	StatusWired                        // Bean has been wired.
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BeanDefinition

type BeanDefinition struct {
	// contains filtered or unexported fields
}

BeanDefinition contains both metadata and runtime information of a bean.

func NewBean

func NewBean(objOrCtor any, ctorArgs ...gs.Arg) *BeanDefinition

NewBean creates a new BeanDefinition.

Parameters:

  • objOrCtor: either a bean instance (struct pointer) or a constructor function
  • ctorArgs: optional arguments for constructor binding, ignored if objOrCtor is not a function

Returns:

  • *BeanDefinition: the created bean definition with metadata and lifecycle information

Panics:

  • if objOrCtor is not a reference type
  • if objOrCtor is nil
  • if constructor function has invalid signature (should be func(...)bean or func(...)(bean, error))
  • if method constructor receives invalid arguments

Examples:

// Create bean from object instance
bean := NewBean(&MyService{})

// Create bean from constructor function
bean := NewBean(NewMyService)

// Create bean from method with owner dependency
parent := NewBean(&Parent{})
child := NewBean((*Parent).CreateChild, parent)

func (*BeanDefinition) BeanID added in v1.3.0

func (d *BeanDefinition) BeanID() gs.BeanID

BeanID returns the bean's identifier.

func (*BeanDefinition) Callable

func (d *BeanDefinition) Callable() *gs_arg.Callable

Callable returns the bean's callable constructor.

func (*BeanDefinition) Caller added in v1.3.0

func (d *BeanDefinition) Caller(skip int) *BeanDefinition

Caller records the source file and line number of the bean.

func (*BeanDefinition) Clone added in v1.3.0

func (d *BeanDefinition) Clone() *BeanDefinition

Clone creates a copy of the BeanDefinition. For pointer beans, a new instance of the underlying type is created. For function beans, the value is shared (functions are immutable in Go). This ensures the cloned BeanDefinition has a separate reflect.Value when necessary.

func (*BeanDefinition) Condition added in v1.3.0

func (d *BeanDefinition) Condition(conditions ...gs.Condition) *BeanDefinition

Condition appends conditions for the bean.

func (*BeanDefinition) Conditions added in v1.3.0

func (d *BeanDefinition) Conditions() []gs.Condition

Conditions returns the list of conditions for the bean.

func (*BeanDefinition) Configuration added in v1.3.0

func (d *BeanDefinition) Configuration(c ...Configuration) *BeanDefinition

Configuration sets configuration (include/exclude) for the bean.

func (*BeanDefinition) DependsOn added in v1.3.0

func (d *BeanDefinition) DependsOn(selectors ...gs.BeanID) *BeanDefinition

DependsOn adds dependencies to the bean.

func (*BeanDefinition) Destroy added in v1.3.0

func (d *BeanDefinition) Destroy(fn any) *BeanDefinition

Destroy sets the bean's destruction function. The destroy function is called before the bean is destroyed. Valid signatures: func(bean) or func(bean) error.

func (*BeanDefinition) DestroyMethod added in v1.3.0

func (d *BeanDefinition) DestroyMethod(method string) *BeanDefinition

DestroyMethod sets the bean's destruction method by name. The method must have signature: func() or func() error.

func (*BeanDefinition) Export added in v1.3.0

func (d *BeanDefinition) Export(exports ...reflect.Type) *BeanDefinition

Export registers interfaces exported by the bean.

func (*BeanDefinition) FileLine added in v1.3.0

func (d *BeanDefinition) FileLine() string

FileLine returns the source file and line number of the bean.

func (*BeanDefinition) GetArgValue added in v1.3.0

func (d *BeanDefinition) GetArgValue(gs.ArgContext, reflect.Type) (reflect.Value, error)

GetArgValue returns the bean’s value for argument injection.

func (*BeanDefinition) GetConfiguration added in v1.3.0

func (d *BeanDefinition) GetConfiguration() *Configuration

GetConfiguration returns the configuration for the bean.

func (*BeanDefinition) GetDependsOn added in v1.3.0

func (d *BeanDefinition) GetDependsOn() []gs.BeanID

GetDependsOn returns the list of dependencies for the bean.

func (*BeanDefinition) GetDestroy added in v1.3.0

func (d *BeanDefinition) GetDestroy() any

GetDestroy returns the bean's destruction function.

func (*BeanDefinition) GetExports added in v1.3.0

func (d *BeanDefinition) GetExports() []reflect.Type

GetExports returns the interfaces exported by the bean.

func (*BeanDefinition) GetInit added in v1.3.0

func (d *BeanDefinition) GetInit() any

GetInit returns the bean's initialization function.

func (*BeanDefinition) GetName added in v1.3.0

func (d *BeanDefinition) GetName() string

GetName returns the bean's name.

func (*BeanDefinition) GetStatus added in v1.3.0

func (d *BeanDefinition) GetStatus() BeanStatus

GetStatus returns the bean's current lifecycle status.

func (*BeanDefinition) GetType added in v1.3.0

func (d *BeanDefinition) GetType() reflect.Type

GetType returns the bean's type.

func (*BeanDefinition) GetValue added in v1.3.0

func (d *BeanDefinition) GetValue() reflect.Value

GetValue returns the bean as reflect.Value.

func (*BeanDefinition) Init added in v1.3.0

func (d *BeanDefinition) Init(fn any) *BeanDefinition

Init sets the bean's initialization function. The init function is called after the bean is created and all dependencies are injected. Valid signatures: func(bean) or func(bean) error.

func (*BeanDefinition) InitMethod added in v1.3.0

func (d *BeanDefinition) InitMethod(method string) *BeanDefinition

InitMethod sets the bean's initialization method by name. The method must have signature: func() or func() error.

func (*BeanDefinition) Interface added in v1.3.0

func (d *BeanDefinition) Interface() any

Interface returns the underlying bean.

func (*BeanDefinition) Name added in v1.3.0

func (d *BeanDefinition) Name(name string) *BeanDefinition

Name sets the bean's name.

func (*BeanDefinition) OnProfiles

func (d *BeanDefinition) OnProfiles(profiles string) *BeanDefinition

OnProfiles adds a creation condition based on active profiles. The bean will only be created if the application's "spring.profiles.active" property contains at least one of the specified profiles. Multiple profiles can be provided as a comma-separated string.

Example:

d.OnProfiles("dev,test")  // bean created if active profile is "dev" or "test"

func (*BeanDefinition) SetFileLine added in v1.3.0

func (d *BeanDefinition) SetFileLine(file string, line int)

SetFileLine sets the source file and line number of the bean.

func (*BeanDefinition) SetStatus

func (d *BeanDefinition) SetStatus(status BeanStatus)

SetStatus sets the bean's current lifecycle status.

func (*BeanDefinition) String

func (d *BeanDefinition) String() string

String returns a human-readable description of the bean.

type BeanStatus

type BeanStatus int8

BeanStatus represents the different lifecycle statuses of a bean.

func (BeanStatus) String

func (status BeanStatus) String() string

String returns a human-readable string for the bean status.

type Configuration added in v1.3.0

type Configuration struct {
	Includes []string // Methods to include
	Excludes []string // Methods to exclude
}

Configuration specifies parameters for configuring beans during registration.

Jump to

Keyboard shortcuts

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