Documentation ¶
Index ¶
- func Add[T interface{}](scope ServiceScope, creator func(*Container) *T)
- func AddByType[T interface{}](serviceType reflect.Type, scope ServiceScope, creator func(*Container) *T)
- func AddSingleton[T interface{}](creator func(*Container) *T)
- func AddSingletonDefault[T interface{}]()
- func AddTransient[T interface{}](creator func(*Container) *T)
- func AddTransientDefault[T interface{}]()
- func AddValue(value interface{})
- func Get[T interface{}]() *T
- func GetArray[T interface{}]() []T
- func GetByType[T interface{}](serviceType reflect.Type) *T
- func GetOptional[T interface{}]() (*T, bool)
- func TryAdd[T interface{}](scope ServiceScope, creator func(*Container) *T)
- func TryAddByType[T interface{}](serviceType reflect.Type, scope ServiceScope, creator func(*Container) *T)
- func TryAddSingleton[T interface{}](creator func(*Container) *T)
- func TryAddSingletonDefault[T interface{}]()
- func TryAddTransient[T interface{}](creator func(*Container) *T)
- func TryAddTransientDefault[T interface{}]()
- func TryAddValue(value interface{})
- type Container
- func (c *Container) Add(descriptor ServiceDescriptor)
- func (c *Container) Get(serviceType reflect.Type) interface{}
- func (c *Container) GetArray(baseType reflect.Type) []interface{}
- func (c *Container) GetOptional(serviceType reflect.Type) (interface{}, bool)
- func (c *Container) TryAdd(descriptor ServiceDescriptor)
- type ServiceCreator
- type ServiceDescriptor
- type ServiceScope
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 AddTransient ¶
func AddTransient[T interface{}](creator func(*Container) *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 TryAddTransient ¶
func TryAddTransient[T interface{}](creator func(*Container) *T)
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) GetOptional ¶
获取对象,如果没有,返回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 )
Click to show internal directories.
Click to hide internal directories.