di

package
v0.0.0-...-9a83fbb Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add[T interface{}](scope ServiceScope, creator func(*Container) *T)

func AddByType

func AddByType[T interface{}](serviceType reflect.Type, scope ServiceScope, creator func(*Container) *T)

func AddSingleton

func AddSingleton[T interface{}](creator func(*Container) *T)

func AddSingletonDefault

func AddSingletonDefault[T interface{}]()

添加 Singleton 无参构造对象

func AddTransient

func AddTransient[T interface{}](creator func(*Container) *T)

func AddTransientDefault

func AddTransientDefault[T interface{}]()

添加Transient无参构造对象

func AddValue

func AddValue(value interface{})

func Get

func Get[T interface{}]() *T

func GetArray

func GetArray[T interface{}]() []T

func GetByType

func GetByType[T interface{}](serviceType reflect.Type) *T

func GetOptional

func GetOptional[T interface{}]() (*T, bool)

func TryAdd

func TryAdd[T interface{}](scope ServiceScope, creator func(*Container) *T)

func TryAddByType

func TryAddByType[T interface{}](serviceType reflect.Type, scope ServiceScope, creator func(*Container) *T)

func TryAddSingleton

func TryAddSingleton[T interface{}](creator func(*Container) *T)

func TryAddSingletonDefault

func TryAddSingletonDefault[T interface{}]()

添加 Singleton 无参构造对象

func TryAddTransient

func TryAddTransient[T interface{}](creator func(*Container) *T)

func TryAddTransientDefault

func TryAddTransientDefault[T interface{}]()

添加Transient无参构造对象

func TryAddValue

func TryAddValue(value interface{})

Types

type Container

type Container struct {
	Services []ServiceDescriptor
	// contains filtered or unexported fields
}

func AddService

func AddService(descriptor ServiceDescriptor) *Container

func CreateContainer

func CreateContainer() *Container

func GetContainer

func GetContainer() *Container

func TryAddService

func TryAddService(descriptor ServiceDescriptor) *Container

func (*Container) Add

func (c *Container) Add(descriptor ServiceDescriptor)

func (*Container) Get

func (c *Container) Get(serviceType reflect.Type) interface{}

func (*Container) GetArray

func (c *Container) GetArray(baseType reflect.Type) []interface{}

func (*Container) GetOptional

func (c *Container) GetOptional(serviceType reflect.Type) (interface{}, bool)

获取对象,如果没有,返回nil

func (*Container) TryAdd

func (c *Container) TryAdd(descriptor ServiceDescriptor)

type ServiceCreator

type ServiceCreator func(c *Container) interface{}

type ServiceDescriptor

type ServiceDescriptor struct {
	ServiceType reflect.Type
	Creator     ServiceCreator
	Scope       ServiceScope
	Value       interface{}
}

func NewServiceDescriptor

func NewServiceDescriptor(serviceType reflect.Type, creator ServiceCreator, scope ServiceScope) ServiceDescriptor

type ServiceScope

type ServiceScope int
const (
	Transient ServiceScope = 0
	Singleton ServiceScope = 1
	Scoped    ServiceScope = 2
)

Jump to

Keyboard shortcuts

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