injecting

package
v1.2.5 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2025 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RefreshDefault = refreshState(iota) // Not refreshed yet
	Refreshing                          // Currently refreshing
	Refreshed                           // Successfully refreshed
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ArgContext

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

ArgContext provides runtime context when calling bean factory functions. It exposes access to configuration properties, bean lookups, condition checks, and allows wiring of parameters during construction.

func NewArgContext

func NewArgContext(c *Injector, stack *Stack) *ArgContext

NewArgContext constructs a new ArgContext for a wiring operation.

func (*ArgContext) Bind

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

Bind binds configuration data into the provided reflect.Value based on the given struct tag.

func (*ArgContext) Check

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

Check evaluates a condition against the current ArgContext.

func (*ArgContext) Find

func (a *ArgContext) Find(s gs.BeanSelector) ([]gs.ConditionBean, error)

Find retrieves beans matching the given selector.

func (*ArgContext) Has

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

Has checks whether a configuration key is present.

func (*ArgContext) Prop

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

Prop retrieves a property value, with optional default.

func (*ArgContext) Wire

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

Wire performs dependency injection on the given reflect.Value using the specified tag, leveraging the current wiring stack.

type BeanRuntime

type BeanRuntime interface {
	Name() string               // The name of the bean
	Type() reflect.Type         // The reflect.Type of the bean
	Value() reflect.Value       // The reflect.Value of the bean
	Interface() any             // The underlying Go interface of the bean
	Callable() *gs_arg.Callable // Optional constructor or factory metadata
	Status() gs_bean.BeanStatus // Lifecycle status of the bean
	String() string             // A readable string representation
}

BeanRuntime defines an interface that provides runtime metadata.

type Injecting

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

Injecting is the IoC component that handles dependency injection and lifecycle management for beans once they have been resolved.

func New

func New(p conf.Properties) *Injecting

New creates a new Injecting instance.

func (*Injecting) Close

func (c *Injecting) Close()

Close shuts down the container by invoking all registered destroyer callbacks in reverse registration order, ensuring dependent resources are released safely.

func (*Injecting) Refresh

func (c *Injecting) Refresh(roots, beans []*gs_bean.BeanDefinition) (err error)

Refresh wires all provided beans and prepares them for use.

It performs the following steps:

  1. Builds indexes for bean lookup by name and type.
  2. Wires root beans (entry points of the dependency graph).
  3. Handles lazy wiring for circular dependencies if allowed.
  4. Captures all registered destroyer callbacks for proper shutdown order.
  5. Optionally cleans up metadata if running outside testing.

func (*Injecting) RefreshProperties

func (c *Injecting) RefreshProperties(p conf.Properties) error

RefreshProperties updates the dynamic property source for the container.

func (*Injecting) Wire

func (c *Injecting) Wire(obj any) error

Wire injects dependencies into an externally provided object.

type Injector

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

Injector is the component that executes core autowiring and bean lifecycle management (constructor, field, and method injection).

type LazyField

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

LazyField represents a field in a struct that should be injected lazily.

type Stack

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

Stack represents the runtime context during bean wiring. It keeps track of the current wiring call stack, lazily injected fields, and the ordering of destroyers for proper shutdown.

func NewStack

func NewStack() *Stack

NewStack creates and initializes a new Stack for a fresh Refresh or Wire operation.

func (*Stack) Path

func (s *Stack) Path() (path string)

Path returns a formatted string representation of the current wiring stack, which is useful for debugging and error messages.

type WireTag

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

WireTag represents the parsed structure of an injection tag in the form "BeanName?" where "?" indicates that the dependency is optional.

func (WireTag) String

func (tag WireTag) String() string

String converts a WireTag back to its string representation.

Jump to

Keyboard shortcuts

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