internal

package
v1.0.0-alpha.25 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DependencyGraph

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

DependencyGraph 依赖图

func NewDependencyGraph

func NewDependencyGraph() *DependencyGraph

func (*DependencyGraph) AddNode

func (g *DependencyGraph) AddNode(key RegistrationKey, dependencies []reflect.Type)

func (*DependencyGraph) TopologicalSort

func (g *DependencyGraph) TopologicalSort() ([]RegistrationKey, error)

type Engine

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

Engine 容器引擎(不导出)

func NewEngine

func NewEngine() *Engine

func (*Engine) Compile

func (e *Engine) Compile() error

Compile 编译容器

func (*Engine) Contains

func (e *Engine) Contains(serviceType reflect.Type, name string) bool

Contains 检查服务是否存在

func (*Engine) GetAllRegistrations

func (e *Engine) GetAllRegistrations() map[RegistrationKey]*Registration

GetAllRegistrations 返回所有注册信息

func (*Engine) GetRegistration

func (e *Engine) GetRegistration(key RegistrationKey) (*Registration, bool)

GetRegistration 获取注册信息

func (*Engine) GetSingletons

func (e *Engine) GetSingletons() []interface{}

GetSingletons 返回所有 Singleton 实例(用于资源清理)

func (*Engine) Register

func (e *Engine) Register(reg *Registration) error

Register 注册服务

func (*Engine) RegisterKeyed

func (e *Engine) RegisterKeyed(reg *Registration, serviceKey string) error

RegisterKeyed 注册命名服务

func (*Engine) Resolve

func (e *Engine) Resolve(serviceType reflect.Type, name string) (interface{}, error)

Resolve 解析服务(只支持 Singleton)

func (*Engine) ResolveAll

func (e *Engine) ResolveAll(serviceType reflect.Type) ([]interface{}, error)

ResolveAll 解析特定类型的所有服务

type GraphNode

type GraphNode struct {
	Key          RegistrationKey
	Dependencies []RegistrationKey
	Visited      bool
	InStack      bool
}

GraphNode 依赖图中的节点

type Registration

type Registration struct {
	ID                 TypeID // 缓存 TypeID 以提高性能
	ServiceType        reflect.Type
	ImplementationType reflect.Type
	Lifetime           ServiceLifetime
	ServiceKey         string // 用于键控服务 (Keyed Services)
	Factory            interface{}
	FactoryValue       reflect.Value
	InputTypes         []reflect.Type
	Interfaces         []reflect.Type
}

Registration 注册信息

type RegistrationKey

type RegistrationKey struct {
	Type reflect.Type
	Name string
}

RegistrationKey 注册键

type ServiceLifetime

type ServiceLifetime int

ServiceLifetime 服务生命周期 简化版本只支持 Singleton

const (
	Singleton ServiceLifetime = iota
)

type TypeID

type TypeID int32

typeID 每一个注册类型唯一的 ID

type TypeRegistry

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

TypeRegistry 负责管理 {Type, Name} 到 TypeID 的映射

func NewTypeRegistry

func NewTypeRegistry() *TypeRegistry

func (*TypeRegistry) Get

func (r *TypeRegistry) Get(t reflect.Type, name string) (TypeID, bool)

Get 检查是否已存在

func (*TypeRegistry) GetID

func (r *TypeRegistry) GetID(t reflect.Type, name string) TypeID

GetID 获取类型的 ID,如果不存在则创建

func (*TypeRegistry) Type

func (r *TypeRegistry) Type(id TypeID) reflect.Type

Type 获取 ID 对应的 Type

Jump to

Keyboard shortcuts

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