sdi4go

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2020 License: MIT Imports: 4 Imported by: 6

README

sdi4go

sid4go(Simple Dependency Injection) library for golang

Usage

for details lookup example

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrName                 = errors.New("object name duplicate")
	ErrNotFound             = errors.New("inject object name not found")
	ErrSingletonConstructor = errors.New("bind function must only provide one option of Singleton or Contructor")
	ErrFactoryType          = errors.New("factory type must be func()(Type,error)")
	ErrSingletonType        = errors.New("singleton type must be struct ptr")
	ErrInjectObject         = errors.New("inject object must be struct ptr")
	ErrInjectField          = errors.New("inject object field must public and must be struct ptr or interface")
	ErrBindType             = errors.New("bind type mismatch inject target field")
	ErrSliceType            = errors.New("CreateAll expect slice ptr which elem type must be interface or struct ptr")
	ErrObjectPtr            = errors.New("Create func expect struct ptr or interface")
)

errors .

View Source
var Debug = false

Debug debug flag , open debug sdi4go will print debug message into console

Functions

This section is empty.

Types

type Factory

type Factory interface{}

Factory .

type Injector

type Injector interface {
	// bind named object creator
	Bind(name string, options ...Option) error
	// Create object with name
	Create(name string, objectPtr interface{}) error
	// inject object fields with tag `inject:"object name"`
	Inject(object interface{}) error
	// CreateAll create special type objects slice
	// this function will search all bind class which must the provide slice type
	CreateAll(objectSlice interface{}) error
}

Injector the golang inject objects sdi4go factory

func New

func New() Injector

New create a new golang struct sdi4go

type Option

type Option func(register *objectRegister)

Option .

func Constructor

func Constructor(f Factory) Option

Constructor bind class with object factory

func Singleton

func Singleton(object interface{}) Option

Singleton bind a singleton class

Jump to

Keyboard shortcuts

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