components

package
v0.9.8 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2023 License: MIT Imports: 1 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Factory

type Factory interface {
	CreateInstance(info Info) (Instance, error)
}

Factory 用于创建组件实例

type Holder

type Holder interface {
	Info() Info
	Factory() Factory
	GetInstance() (Instance, error)
	NewRef(sel Selector) Ref
}

Holder 根据作用域,持有一个或一组组件实例

type ID

type ID string

ID 表示一个组件ID

func (ID) String

func (id ID) String() string

type Info

type Info interface {
	ID() ID
	Aliases() []string
	Classes() []string
	Scope() Scope
}

Info 提供组件的相关信息

type Injection

type Injection interface {
	context.Context

	Select(selector Selector) ([]Instance, error)

	SelectOne(selector Selector) (Instance, error)

	GetByID(id ID) (Instance, error)

	GetApplicationContext() context.Context

	GetProperty(selector Selector) (string, error)

	GetWithHolder(holder Holder) (Instance, error)

	Scope() Scope
}

Injection 表示一个依赖注入上下文

type Instance

type Instance interface {
	Ready() bool
	Get() any
	Info() Info
	Inject(i Injection) error
}

Instance 用于创建组件实例

type Ref

type Ref interface {
	Selector() Selector
	Holder() Holder
}

Ref 表示一个对 Holder 的引用

type Scope

type Scope int

Scope 表示组件的作用域

const (
	ScopeSingleton Scope = 1
	ScopePrototype Scope = 2
)

定义组件的各种作用域

type Selector

type Selector string

Selector 表示一个组件选择器

func SelectorForAlias

func SelectorForAlias(alias string) Selector

SelectorForAlias 创建 alias 选择器

func SelectorForClass

func SelectorForClass(cname string) Selector

SelectorForClass 创建 class 选择器

func SelectorForID

func SelectorForID(id ID) Selector

SelectorForID 创建 ID 选择器

func (Selector) String

func (sel Selector) String() string

type Table

type Table interface {
	Get(id ID) (Holder, error)
	Put(h Holder) error
	Select(selector Selector) ([]Holder, error)
	ListIDs() []ID

	Export(dst map[ID]Holder) map[ID]Holder
	Import(src map[ID]Holder)
}

Table 表示一个组件的集合

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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