inject

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2020 License: Apache-2.0 Imports: 3 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Ioc

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

Ioc 控制反转,Inversion of Control

func NewIoc

func NewIoc(
	enableUnexportedFieldSetValue bool,
) *Ioc

func (*Ioc) Inject

func (ioc *Ioc) Inject(v interface{}) (err error)

Inject 注入依赖

遍历v的字段,找到字段类型,再根据字段类型找到provider,调用provider获得实例,再把实例值赋给该字段 provider需要在接口定义处注册,注册到一个统一管理的地方 如果provider需要参数,则根据参数类型继续找寻相应的provider,直至初始化完成

func (*Ioc) RegisterProvider

func (ioc *Ioc) RegisterProvider(v interface{}) (err error)

RegisterProvider 注册provider

Jump to

Keyboard shortcuts

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