injecting

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: 21 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(beanID gs.BeanID) ([]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) (string, bool)

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 Injecting

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

Injecting is the core IoC container component. It handles bean creation, dependency injection, lifecycle management, dynamic property updates, and destroy callbacks.

func New

func New(p flatten.Storage) *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. The destroyers are executed in reverse order respecting dependency relationships, ensuring that beans are destroyed after the beans they depend on. Any errors returned from destroy methods are logged but do not stop the shutdown process.

func (*Injecting) DynamicObjectsCount added in v1.3.0

func (c *Injecting) DynamicObjectsCount() int

DynamicObjectsCount returns the number of objects that can be dynamically refreshed.

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 operations:

  1. Builds indexes for bean lookup by name and type (by name and by type).
  2. Wires all root beans (entry points of the dependency graph), recursively wiring dependencies.
  3. Handles fields tagged with ',lazy' for deferred injection. Note: lazy wiring only applies to explicitly marked fields and does not resolve arbitrary circular dependencies.
  4. Registers destroyer callbacks for beans in dependency-safe order.
  5. Cleans up metadata.

Behavior is influenced by properties: - spring.allow-circular-references: whether lazy circular references are allowed. - spring.force-autowire-is-nullable: whether missing dependencies are treated as nullable.

func (*Injecting) RefreshProperties

func (c *Injecting) RefreshProperties(p flatten.Storage) error

RefreshProperties updates the dynamic properties in the container.

type InjectionError added in v1.3.0

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

InjectionError wraps an injection failure at a specific field path.

func (*InjectionError) Error added in v1.3.0

func (e *InjectionError) Error() string

Error formats the error with the field path and the root error.

func (*InjectionError) Path added in v1.3.0

func (e *InjectionError) Path() string

Path returns the full field path where injection failed.

func (*InjectionError) Unwrap added in v1.3.0

func (e *InjectionError) Unwrap() error

Unwrap returns the root error.

type Injector

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

Injector performs core dependency injection and bean lifecycle management. Responsibilities include: - Constructor invocation and creation of bean values. - Field injection and wiring of struct dependencies. - Initialization callbacks execution. - Bean status management (creating, created, wired). - Lazy field handling and circular dependency detection. - Respecting forceAutowireIsNullable flag to treat missing dependencies as optional.

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.

type WireTag

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

WireTag represents the parsed structure of an injection tag. Format: "BeanName?" where "?" marks the dependency as nullable.

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