container

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bind

func Bind[T any](c *Container, resolver func(c *Container) T)

Bind 注册普通服务(泛型版本)

func Instance

func Instance[T any](c *Container, instance T)

Instance 直接注册实例(泛型版本)

func Make

func Make[T any](c *Container) (T, error)

Make 解析服务(泛型版本)

func MustMake

func MustMake[T any](c *Container) T

MustMake 解析服务,如果失败则 panic

func Singleton

func Singleton[T any](c *Container, resolver func(c *Container) T)

Singleton 注册单例服务(泛型版本)

Types

type Container

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

Container 泛型 IoC 容器,提供类型安全的依赖注入

func New

func New() *Container

New 创建新的容器实例

func (*Container) Alias

func (c *Container) Alias(abstract, alias string)

Alias 为服务创建别名

func (*Container) BindInterface

func (c *Container) BindInterface(interfaceName string, resolver func(c *Container) any, shared bool)

BindInterface 绑定接口到实现(需要手动指定类型名)

func (*Container) Flush

func (c *Container) Flush()

Flush 清空容器

func (*Container) Has

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

Has 检查服务是否已注册

func (*Container) MakeByName

func (c *Container) MakeByName(abstract string) (any, error)

MakeByName 通过名称解析服务(非泛型版本,用于接口)

Jump to

Keyboard shortcuts

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