Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrBeanIdParamIsEmpty = errors.New("beanID parameter is empty") ErrBeanTypeParamIsNil = errors.New("beanType parameter is nil") ErrBeanParamIsNil = errors.New("bean parameter is nil") ErrBeanTypeNotSupported = errors.New("beanType is not supported") ErrRegistrationClosed = errors.New("container already built; registration is closed") )
Functions ¶
func ResolveAs ¶
ResolveAs returns a bean instance by its ID and casts it to type T. It ensures the container is built before resolving and returns an error on failure.
func SetLiteralProvider ¶
func SetLiteralProvider(p LiteralProvider)
SetLiteralProvider installs a global literal provider hook. A typical implementation might read env vars, files, flags, or other configuration sources.
Types ¶
type Container ¶
type Container struct {
// contains filtered or unexported fields
}
func (*Container) Build ¶
Build finalizes the container by verifying all required dependencies are registered, instantiating all registered beans, and injecting dependencies.
If the container has already been built, this method is a no-op.
func (*Container) Register ¶
Register registers a bean by its reflect.Type. If the type is a struct, it will be normalized to a pointer-to-struct for consistent injection semantics. The 'beanID' parameter is case-sensitive with regard to the bean identifier and the coresponding receiving bean tag. The case of the bean identifier must match the case of the tag in the receiving bean.
This method only supports registering structs and pointers to structs; simple types (e.g., string) must be registered as instances using RegisterInstance.
func (*Container) RegisterInstance ¶
RegisterInstance registers a concrete instance for type T. The instance is treated as a singleton. Struct instances are normalized to pointers. The 'beanID' parameter is case-sensitive with regard to the bean identifier and the coresponding receiving bean tag. The case of the bean identifier must match the case of the tag in the receiving bean.
type Initializer ¶
type Initializer interface {
Initialize() error
}
Initializer is an optional interface that a bean may implement to perform additional initialization after all of its dependencies have been injected.
Beans implementing this interface must define Initialize() error. The container will call Initialize() during Build(), after dependency injection has completed. If Initialize returns an error, Build() will fail with that error.
Note: This interface is intentionally defined in the root iocdi package with no imports and no references to internal container types to avoid introducing cyclic dependencies when implemented by beans in other modules/packages.
type LiteralProvider ¶
LiteralProvider is a hook invoked when a dependency with a given id is missing. - id: the value of the `di.inject` tag for the missing dependency - targetType: the type expected for that dependency (e.g., reflect.TypeOf("") for string) Returns: - value: the literal value to use for injection - found: whether a value is available - err: any error occurred while sourcing the value (e.g., parsing, I/O)