dij

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2022 License: MIT Imports: 5 Imported by: 4

Documentation

Index

Constants

View Source
const (
	TagName      = "di"
	StackDeepKey = "__stack_deep__*"
	StackKey     = "__stack__*"
)

Variables

View Source
var LogEnabled = false

Functions

func BuildAnyInstance added in v0.0.9

func BuildAnyInstance(rootInstPtr any, referencePtr DependencyReferencePtr, instName string) (any, error)

func BuildInstance added in v0.0.6

func BuildInstance[T any](rootInstPtr *T, referencePtr DependencyReferencePtr, instName string) (*T, error)

func CallDependencyInjection

func CallDependencyInjection(initMethod reflect.Method, inst any, reference DependencyReferencePtr) error

func CreateInstance

func CreateInstance(rootTyp reflect.Type, referencePtr DependencyReferencePtr, instName string) (any, error)

func EnableLog

func EnableLog()

func FullnameOfType

func FullnameOfType(typ reflect.Type) string

func GetMethodForReceiverType

func GetMethodForReceiverType(typ reflect.Type, fnName string) (reflect.Method, bool)

GetMethodForReceiverType Get method for a receiver whose type is typ.

func SetUnexportedField

func SetUnexportedField(field reflect.Value, value interface{})

Types

type DependencyKey

type DependencyKey = string

type DependencyReference

type DependencyReference map[DependencyKey]any

type DependencyReferencePtr

type DependencyReferencePtr = *DependencyReference

func (DependencyReferencePtr) Get

func (r DependencyReferencePtr) Get(key string) (any, bool)

Get retrieves the dependent object.

func (DependencyReferencePtr) GetForDiField

func (r DependencyReferencePtr) GetForDiField(insTyp reflect.Type, fieldIndex int) (any, bool)

GetForDiField retrieves the injected instance for field

func (DependencyReferencePtr) StackCount

func (r DependencyReferencePtr) StackCount() int

StackCount shows current stack count when running dependency inject. It should always be zero after run over CreateInstance. Just for debug.

func (DependencyReferencePtr) StackHistory

func (r DependencyReferencePtr) StackHistory() (stack DependencyStack)

StackHistory retrieves the history for running dependency injection

type DependencyStack

type DependencyStack []*DependencyStackRecord

func (DependencyStack) GetRecord

func (s DependencyStack) GetRecord(index int) *DependencyStackRecord

func (DependencyStack) NumOfRecords

func (s DependencyStack) NumOfRecords() int

type DependencyStackRecord

type DependencyStackRecord struct {
	Inst     any
	Deep     int
	Fullname string
}

func (DependencyStackRecord) InstType

func (r DependencyStackRecord) InstType() reflect.Type

func (DependencyStackRecord) NameOfInstType

func (r DependencyStackRecord) NameOfInstType() string

type DiTag

type DiTag struct {
	Exists  bool // explicitly set tag string, the value false means doesn't use Dependency Injection.
	Enabled bool // the tag with '-' name means not enable explicitly, the value false means doesn't use Dependency Injection.
	// contains filtered or unexported fields
}

func ParseDiTag

func ParseDiTag(insTyp reflect.Type, fieldIndex int) (diTag DiTag, err error)

ParseDiTag parses the tag with 'di' key.

type InitializationHandler

type InitializationHandler interface {
	// DidDependencyInitialization will be called after initialization is completed. If receiver implements InjectionHandler
	// interface, InjectionHandler.DidDependencyInjection will be called first.
	DidDependencyInitialization()
}

type InjectionHandler

type InjectionHandler interface {
	// DidDependencyInjection will be called after injection is completed.
	DidDependencyInjection()
}

Jump to

Keyboard shortcuts

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