Documentation
¶
Index ¶
- type DependencyGraph
- type Engine
- func (e *Engine) Compile() error
- func (e *Engine) Contains(serviceType reflect.Type, name string) bool
- func (e *Engine) GetAllRegistrations() map[RegistrationKey]*Registration
- func (e *Engine) GetRegistration(key RegistrationKey) (*Registration, bool)
- func (e *Engine) GetSingletons() []interface{}
- func (e *Engine) Register(reg *Registration) error
- func (e *Engine) RegisterKeyed(reg *Registration, serviceKey string) error
- func (e *Engine) Resolve(serviceType reflect.Type, name string) (interface{}, error)
- func (e *Engine) ResolveAll(serviceType reflect.Type) ([]interface{}, error)
- type GraphNode
- type Registration
- type RegistrationKey
- type ServiceLifetime
- type TypeID
- type TypeRegistry
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 (*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) RegisterKeyed ¶
func (e *Engine) RegisterKeyed(reg *Registration, serviceKey string) error
RegisterKeyed 注册命名服务
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 ¶
RegistrationKey 注册键
type ServiceLifetime ¶
type ServiceLifetime int
ServiceLifetime 服务生命周期 简化版本只支持 Singleton
const (
Singleton ServiceLifetime = iota
)
type TypeRegistry ¶
type TypeRegistry struct {
// contains filtered or unexported fields
}
TypeRegistry 负责管理 {Type, Name} 到 TypeID 的映射
func NewTypeRegistry ¶
func NewTypeRegistry() *TypeRegistry
Click to show internal directories.
Click to hide internal directories.